Adapt DateTime values for SQL-Server or Access formats
The following functions converts a datatime value (independant of the dateformat) to a string that is readable by the SQL Server.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
function DateTimeToSQLServerDateTimeString(Value: TDateTime): string; begin Result := '{ ts' + QuotedStr(FormatDateTime('yyyy-mm-dd hh":"nn":"ss.z', Value)) + ' }'; end;function DateTimeToSQLServerDateString(Value: TDateTime): string; begin Result := '{ d' + QuotedStr(FormatDateTime('yyyy-mm-dd', Value)) + ' }'; end; function DateTimeToSQLServerTimeString(Value: TDateTime): string; begin Result := '{ t' + QuotedStr(FormatDateTime('hh":"nn":"ss.z', Value)) + ' }'; end; {also for the Jet-Engine (Access database)} function DateTimeToAccessDateTimeString(Value: TDateTime): string; function FloatToStrEx(const Value: Extended; const DecSep: Char): string; var OldSep: Char; begin OldSep := DecimalSeparator; try DecimalSeparator := DecSep; Result := FloatToStr(Value); finally DecimalSeparator := OldSep; end; end; begin // because Access (Jet-Engine) stores a date as a double... Result := FloatToStrEx(Value, '.'); end; |