0

My system date time format is "dd-MM-yy". And in my db the date is stored like "04/12/12" when i try to convert the string to date using the following code i am getting exception

formatSettings := TFormatSettings.Create(LOCALE_SYSTEM_DEFAULT);
Result := StrToDateTime(sDateTime, formatSettings);

when i examined the format settings the ShortDateFormat is "dd/MM/yy" and the DateSeparator is coming as "-" but when i hard code my dateseperator to "/" it is working fine but is that the correct approach?

Jeeva
  • 4,585
  • 2
  • 32
  • 56
  • I'm not surprised: "04/12/12" is an extremely pathological format for a date. – Bathsheba Jul 04 '13 at 07:32
  • Yes, it's perfectly fine to change format settings. But declare your own, separate variable for that. Don't modify the global `FormatSettings` variable given to you by Delphi for this purpose. – TLama Jul 04 '13 at 07:34
  • is there anyway we can pickup the dateseperator dynamically? and my confusion is mainly when my system format is dd-mm-yy how come the formatsettings date format is wrong and dateseperator is correct? – Jeeva Jul 04 '13 at 07:41
  • why do you think it is wrong ? it only means someone stored dates into your database as-string instead of as-date, and he used tat weird exotic format for this, it does tell nothing about settings of your OS or Delphi RTL – Arioch 'The Jul 04 '13 at 07:53

0 Answers0