//入参 YYYYMMDDHHmmss 返回 datetime
function ConvertStrToDateTime(DateTimeStr : string;var ADateTime : TDateTime) : boolean;
var
Y,M,D,H,N,S : Integer;
begin
Result := False;
if StrIsValidDateTime(DateTimeStr,Y,M,D,H,N,S) then
begin
ADateTime := EncodeDatetime(Y,M,D,H,N,S,0);
Result := True;
end;
end;
//判断是否是日期时间
function StrIsValidDateTime(DateTimeStr : string; var Y,M,D,H,N,S : Integer) : boolean;
begin
Result := False;
if TryStrToInt(Copy(DateTimeStr,1,4),Y) then
begin
if TryStrToInt(Copy(DateTimeStr,5,2),M) then
begin
if TryStrToInt(Copy(DateTimeStr,7,2),D) then
begin
if TryStrToInt(Copy(DateTimeStr,9,2),H) then
begin
if TryStrToInt(Copy(DateTimeStr,11,2),N)then
begin
if TryStrToInt(Copy(DateTimeStr,13,2),S) then
begin
Result := IsValidDateTime(Y,M,D,H,N,S,0);
end;
end;
end;
end;
end;
end;
end;
03-11
1955
07-10