Παρασκευή 2 Μαρτίου 2012

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 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;
{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;

Δεν υπάρχουν σχόλια:

Δημοσίευση σχολίου