Name
VarToDateTime Function
Syntax
function VarToDateTime(const V: Variant): TDateTime;
Description
VarToDateTime
converts a Variant
to a TDateTime. If the Variant
cannot be converted to varDate, the function
reports runtime error 15
(EVariantError).
VarToDateTime is a real function.
Tips and Tricks
Assigning a
Variantto aTDateTimevariable does not work. BecauseTDateTimeis a floating-point type, the assignment would try to convert theVariantto avarDouble, not avarDate.VarToDateTimeeventually calls the Windows API functionVariantChangeTypeExto parse the string and interpret the date and time. See the Platform SDK documentation for details.VarToDateTimeaccepts many more formats thanStrToDateTime.
Example
// Parse a string as a date and time.
function StringToDateTime(const S: string): TDateTime;
var
V: Variant;
begin
V := S;
Result := VarToDateTime(V);
end;See Also
| TDateTime Type, VarFromDateTime Function, Variant Type |
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access