Thoughts from Dan Miser RSS 2.0
 Monday, January 09, 2006
For quite some time, Delphi has allowed custom FormatSettings to be used with many date/time functions. This allows you to use custom date/time settings within an application without changing the Windows options. For example, if you used this code snippet and had a date/time format like mm/dd/yyyy, you would see the date/time reported in the new format instead:

procedure TForm3.Button1Click(Sender: TObject);
var
  MySettings: TFormatSettings;
  s: string;
  d: TDateTime;
begin
  GetLocaleFormatSettings(GetUserDefaultLCID, MySettings);
  MySettings.DateSeparator := '-';
  MySettings.TimeSeparator := ':';
  MySettings.ShortDateFormat := 'mm-dd-yyyy';
  MySettings.ShortTimeFormat := 'hh:nn:ss';

  s := DateTimeToStr(Now, MySettings);
  ShowMessage(s);
  d := StrToDateTime(s, MySettings);
  ShowMessage(DateTimeToStr(d, MySettings));
end;

However, if you used 'mmm-dd-yyyy' as the ShortDateFormat in the example above (to display Jan-09-2006), you would get an error when calling StrToDateTime on this string. The workaround is to call d := VarToDateTime(s) instead, since that function supports month names when encoding the TDateTime. I logged this bug as QC 23301, so if you'd like to see this fixed, please rate this entry and vote on it if it's important enough to you.

Monday, January 09, 2006 8:08:00 PM (Central Standard Time, UTC-06:00)  #    Comments [3] -
Delphi
Tracked by:
http://9qm-information.info/03416371/vendita-animale-cavallo-zona-sicilia.html [Pingback]
http://9os-information.info/01327490/index.html [Pingback]
http://9ou-information.info/66397032/index.html [Pingback]
http://9om-information.info/72024957/restaurant-gift-certificate-templates.html [Pingback]
http://9qc-information.info/76110691/biological-science.html [Pingback]
http://9om-information.info/09978748/neals-police-bars-evidence-cash.html [Pingback]
http://9oy-information.info/86374730/kung-fu-tv-series-on-dvd.html [Pingback]
http://9so-information.info/54201576/index.html [Pingback]
http://9rx-information.info/45882205/hilary-duff-school-disco.html [Pingback]
http://9sg-information.info/74012361/index.html [Pingback]
http://9sh-information.info/75088355/index.html [Pingback]
http://9sr-information.info/13510475/vada-agriturismo-tripesce.html [Pingback]
http://9rf-information.info/86356833/american-school-home-schooling.html [Pingback]
http://9uaeb-le-informazioni.info/60425801/treat-her-like-a-lady.html [Pingback]
http://9uaff-le-informazioni.info/80960198/file-sga.html [Pingback]
http://9uaeh-le-informazioni.info/12261747/gioco-garfield.html [Pingback]
http://9uafc-le-informazioni.info/58166118/index.html [Pingback]
http://9uaei-le-informazioni.info/56061567/orient-watches.html [Pingback]
http://9uafi-le-informazioni.info/17374777/index.html [Pingback]
http://9uafe-le-informazioni.info/25500825/index.html [Pingback]
http://9uafh-le-informazioni.info/90341285/reddito-familiare-a-carico.html [Pingback]
http://9uagt-le-informazioni.info/53083524/index.html [Pingback]
http://9uagj-le-informazioni.info/61481845/index.html [Pingback]
http://9uagm-le-informazioni.info/06573526/brescia-come-arrivare.html [Pingback]
http://9uagd-le-informazioni.info/58030132/index.html [Pingback]
http://9uago-le-informazioni.info/05748746/part-time-work.html [Pingback]
http://9uaga-le-informazioni.info/67841052/istituto-superiora-blaise-pascal-pome... [Pingback]
http://9uahb-le-informazioni.info/64074616/index.html [Pingback]
http://9uaht-le-informazioni.info/46889833/voli-da-reggio-calabria.html [Pingback]
Wednesday, January 11, 2006 8:46:00 AM (Central Standard Time, UTC-06:00)
This is not limited to only mmm-dd-yyyy formats, but also international date formats with mmm as the month name. Any solution should handle foreign month names (based on regional settings) in addition to the standard english month names.



I will post this information to the bug report. I was able to work around this problem by writing my own functions for StrToDate and StrToDateTime.
Wednesday, January 11, 2006 9:02:00 AM (Central Standard Time, UTC-06:00)
That would be great to update the report with your info. I haven't tried with international date times, but I would think it *should* work when the bug is fixed if you update the TFormatSettings with the month names for the target country.



Also, does VarToDateTime work with international month names now?
Friday, May 19, 2006 5:32:00 AM (Central Standard Time, UTC-06:00)
Facing problem doing StrtoDateTime('19-May-2006 10:30:30')
Rup Sen
Comments are closed.
Navigation
Archive
<August 2008>
SunMonTueWedThuFriSat
272829303112
3456789
10111213141516
17181920212223
24252627282930
31123456
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2008
Dan Miser
Sign In
Statistics
Total Posts: 307
This Year: 22
This Month: 1
This Week: 1
Comments: 604
All Content © 2008, Dan Miser
DasBlog theme 'Business' created by Christoph De Baene (delarou)