Delphi 关于日期时间转字符的调用函数,在Delphi11.3/12里调试通过
--日期时间转字符
function DateTimeToSQLStr(InpDateTime: TDateTime;
IsParadox: Boolean = False; IsIncludeMSecond: Boolean = False): string;
var
sDate: string;
sTime: string;
begin
sDate := DateToSQLStr(InpDateTime, IsParadox);
System.Delete(sDate, Length(sDate), 1);
sTime := Copy(TimeToSQLStr(InpDateTime, IsIncludeMSecond), 2, MaxInt);
Result := sDate+ STR_SPACE+ sTime;
end;
--日期转字符
function DateToSQLStr(InpDate: TDateTime; IsParadox: Boolean = False): string;
var
nYear: Word;
nMonth: Word;
nDay: Word;
begin
if (not IsParadox) then
Result := FormatDateTime(SQL_DATE_FORMAT, InpDate)
else
begin
DecodeDate(InpDate, nYear, nMonth, nDay);
Result := Copy(SQL_MONTH_STRING, (nMonth- 1)* 3+ 1, 3);
Result := Format(SQL_PARADOX_DATE_FORMAT, [nDay, Result, nYear]);
end;
Result := QuotedStr(Result);
end;
--时间转字符
function TimeToSQLStr(InpTime: TDateTime;
IsIncludeMSecond: Boolean = False): string;
var
sTime: string;
begin
sTime := SQL_TIME_FORMAT;
if (IsIncludeMSecond) then
sTime := sTime+ SQL_MSEC_FORMAT;
Result := QuotedStr(FormatDateTime(sTime, InpTime));
end;