Mega Code Archive

 
Categories / Delphi / ADO Database
 

How to adapt DateTime values for SQL Server or Access formats

Title: How to adapt DateTime values for SQL-Server or Access formats 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;