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 31
| function DateSqlToTDateTime(const S: string): TDateTime;
var
AAAA, MM, JJ: word;
HH, MN, SS, MS: word;
begin
//1234567890123456789
//2016-08-15 01:02:03
AAAA := StrToIntDef(Copy(S, 1, 4), 2000);
MM := StrToIntDef(Copy(S, 6, 2), 01);
JJ := StrToIntDef(Copy(S, 9, 2), 01);
HH := StrToIntDef(Copy(S, 12, 2), 00);
MN := StrToIntDef(Copy(S, 15, 2), 00);
SS := StrToIntDef(Copy(S, 18, 2), 00);
MS := 0;
Result := EncodeDateTime(AAAA, MM, JJ, HH, MN, SS, MS);
end;
// encodage d'une date en format SQL
function DateTimeToDateSql(const QD: TDateTime): string;
const
SQL_DATE_HEURE_FORMAT = '%.4d-%.2d-%.2d %.2d:%.2d:%.2d';
var
QAnnee, QMois, QJour, QHeure, QMinute, QSeconde, QMilliseconde: word;
begin
DecodeDate(QD, QAnnee, QMois, QJour);
DecodeTime(QD, QHeure, QMinute, QSeconde, QMilliseconde);
Result := Format(SQL_DATE_HEURE_FORMAT,
[QAnnee, QMois, QJour,
QHeure, QMinute, QSeconde, QMilliseconde
]);
end; |
Partager