AM/PM Issue
'8/19/2004 3:19:43 PM' Fails '8/19/2004 15:19:43' OK 'now' current datetimeBoth Delphi and Firebird support a now construct
DateTimeToStr fails
DateTime := DateTimeToStr(Now); // CREATE TABLE "xyz_tbl" ( // "xyz_ID" VARCHAR(5) NOT NULL /* "Experiment_ID" */ , // "Date_Time" TIMESTAMP /* "Date_Time" */ // ); s := 'INSERT into "xyz_tbl" ' + '("xyz_ID", "Date_Time")' + ' Values (''' + Experiment_ID + ''', ''' + DateTime + '''' + ' ) ' ; ExecuteSQL(s); // a routine I wroteOn my system
LongTimeFormat = 'h:mm:ss AMPM'which produces the standard 12 hour clock format
'1/30/2005 3:06:32 AM'that fails with Firebird.
Notice that LongTimeFormat uses mm for both month and minutes, but that nn always produces minutes. From the Delphi help
mm Displays the month as a number with a leading zero (01-12). If the mm specifier immediately follows an h or hh specifier, the minute rather than the month is displayed.Tests indicate that LongTimeFormat is not a system variable, meaning that once you change its value, you do not have to restore it. In other words, changes made by your program only affect your program.
Here are some miscellaneous instructions used to format date/times
DT_Str := Date + ' ' + Time; DT := StrToDateTime(DT_Str); DateTimeToString(DT_Str, 'mm/dd/yyyy hh:mm:ss am/pm', DT);// ok for display, not for Firebird DateTimeToString(d, 'yyyymmdd', DT); DateTimeToString(m, 'yyyymmdd_hhnnss', DT);
// This routine accepts any valid date/time format // and produces a date/time in 24 hour format // without the am/pm specifiers // Firebird queries fail if am or pm is present function TBasicDataModule.DateTime_to_24hr(DateTime: string): string; var dt_str : string; dt : TDateTime; begin if CompareText(DateTime, 'now')=0 then begin // case insensitive dt_str := FormatDateTime('mm/dd/yyyy hh:nn:ss', Now); end else begin dt := StrToDateTime (DateTime); dt_str := FormatDateTime('mm/dd/yyyy hh:nn:ss', dt); end; result := dt_str; end;
UTC
Local DateTime | Used with the user interface |
UTC DateTime | Simplifies computations |
UTC offset in effect at that location on that day |
Warning: | In some cases (such as file dates), Windows shows different times for the same value depending on the month of the year (ie, whether or not daylight savings time is in effect). |
References