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
Variant
to aTDateTime
variable does not work. BecauseTDateTime
is a floating-point type, the assignment would try to convert theVariant
to avarDouble
, not avarDate
.VarToDateTime
eventually calls the Windows API functionVariantChangeTypeEx
to parse the string and interpret the date and time. See the Platform SDK documentation for details.VarToDateTime
accepts 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 |
Get Delphi in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.