...adapt DateTime values for SQL-Server or Access formats?

Author: Andreas Schmidt

Category: Database

{---------------------------------------------------------------------

Dieser Tip ist als Verbesserung zum ursprünglichen Artikel
http://www.swissdelphicenter.ch/de/showcode.php?id=1423
gedacht.

Die folgende Funktionen wandeln einen DateTime Wert
(unabhängig vom eingestelltem Datumsformat) in einen
für den SQL-Server verständlichen String um.

----------------------------------------------------------------------

Please also take a look at the initial tip:
http://www.swissdelphicenter.ch/de/showcode.php?id=1423

the following functions converts a datatime value
(independant of the dateformat) to a string that
is readably by the SQL Server

---------------------------------------------------------------------}

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;

{
dito für die Jet-Engine (Access-Datenbank)
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
// Da Access (Jet-Engine) ein Datum als Double speichert...
// because Access (Jet-Engine) stores a date as a double...
Result := FloatToStrEx(Value, '.');
end;

 

printed from
www.swissdelphicenter.ch
developers knowledge base