-1
System.SysUtils.FormatSettings.DateSeparator := '-';
result := StrToDateTime(Trim(val));
System.SysUtils.FormatSettings.DateSeparator := '/';

val Before = '10-23-2008 11:43:54'

Result After = 10/23/2008 11:43:54 AM

Clearly the DateSeparator was not set. Why?

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
S bossen
  • 87
  • 1
  • 5

1 Answers1

0

You are setting DateSeparator before calling StrToDateTime() (FYI, you should be using the TFormatSettings overloaded version of StrToDateTime(), not using the global System.SysUtils.FormatSettings variable at all). Clearly the DateSeparator did take effect to produce the Result you have shown.

Your Result is a TDateTime, not a String. If you are evaluating the Result in the debugger, then setting the RTL's formatting variables at runtime has no effect on the debugger. If you are evaluating the Result some other way, you did not show/explain how.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770