{
Wenn man mit verschiedensprachigen (MS-)SQL-Servern arbeitet,
hat man ab und an das Problem, Datumswerte in ein fur den
jeweiligen Server verstandliches Format umzuwandeln.
}{
If you work with different (MS-)SQL-Server, you have sometimes the
problem what the date value is in the correct format.
}function TForm1.GetSQLDateTimeFormat(UDL: string): string;
begin
Screen.Cursor := crSQLWait;
if ADOConnection1.Connected then ADOConnection1.Close;
ADOConnection1.ConnectionString := "FILE NAME=" + UDL;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add("sp_helplanguage @@LANGUAGE");
Application.ProcessMessages;
trytry
ADOQuery1.Open;
excepton E: Exception do MessageBox(Handle,
PChar("Die Abfrage konnte nicht geoffnet werden:" + #13#10+#13#10+E.Message),
PChar("Fehler!"), 16);
end;
if (ADOQuery1.Active) and (ADOQuery1.RecordCount > 0) then
Result := ADOQuery1.FieldByName("dateformat").AsString;
finally
Screen.Cursor := crDefault;
end;
end;
function DateTimeToSQLDateTimeString(Data: TDateTime; Format: string;
OnlyDate: Boolean = True): string;
var
y, m, d, h, mm, s, ms: Word;
begin
DecodeDate(Data, y, m, d);
DecodeTime(Data, h, mm, s, ms);
if Format = "dmy" then
Result := IntToStr(d) + "-" + IntToStr(m) + "-" + IntToStr(y)
elseif Format = "ymd" then
Result := IntToStr(y) + "-" + IntToStr(m) + "-" + IntToStr(d)
elseif Format = "ydm" then
Result := IntToStr(y) + "-" + IntToStr(d) + "-" + IntToStr(m)
elseif Format = "myd" then
Result := IntToStr(m) + "-" + IntToStr(y) + "-" + IntToStr(d)
elseif Format = "dym" then
Result := IntToStr(d) + "-" + IntToStr(y) + "-" + IntToStr(m)
else
Result := IntToStr(m) + "-" + IntToStr(d) + "-" + IntToStr(y); //mdy: ; //US ifnot OnlyDate then
Result := Result + " " + IntToStr(h) + ":" + IntToStr(mm) + ":" + IntToStr(s);
end;
//Example: //Beispiel: procedure ConvertSQLDateTime;
begin
ShowMessage(DateTimeToSQLDateTimeString(now, GetSQLLanguage("C:\DBEngl.udl")));
end;
Если Вас заинтересовала или понравилась информация по разработке на Delph - "Адаптация значения даты или времени к различным форматам SQL-сервера", Вы можете поставить закладку в социальной сети или в своём блоге на данную страницу: Так же Вы можете задать вопрос по работе этого модуля или примера через форму обратной связи, в сообщение обязательно указывайте название или ссылку на статью!