Delphi 字符串转日期,强大到窒息,困扰了很久

procedure THRForm.Button1Click(Sender: TObject);
var
  D:TDateTime;
  s:string;
begin
  D:=VarToDateTime(05-10-14 04:35PM);
  S:=FormatDatetime(YYYY-MM-DD HH:MM:SS,D);
  showmessage(s);
end;

 

尤其是在进行数据库语句操作时,对于字符串的来源不确定因素太多,有了该函数用起来真的很方便。举例如下:

FQuery.Parameters.ParamValues[Brithday]  := IfThen(edit1.Text= ‘‘, VarToStr(Null), VarToDateTime(edit1.Text));