VariantsVarToDateTime (Delphi)
Description
This example demonstrates the use of the VarToDateTime function in the Variants unit.
Code
var
LDate: TDateTime;
VDateString: Variant;
LStr: String;
begin
{ Wait for user input. }
Write('Write an input date/time (MM/DD/YYYY): '); Readln(LStr);
{ Assign the string to a Variant. }
VDateString := LStr;
try
{ Convert the preassigned Variant to TDateTime. }
LDate := VarToDateTime(VDateString);
{ Write the value to the console. }
Writeln(DateTimeToStr(LDate));
Readln;
except
on EVariantTypeCastError do
begin
Writeln('Invalid date/time string supplied!');
Exit;
end;
end;
end.
Uses
- System.Variants.VarToDateTime ( fr | de | ja )
- System.SysUtils.DateTimeToStr ( fr | de | ja )
- System.Variant ( fr | de | ja )
- System.TDateTime ( fr | de | ja )