Name
VarFromDateTime Function
Syntax
function VarFromDateTime(DateTime: TDateTime): Variant;
Description
VarFromDateTime creates a
varDate
Variant for the given
TDateTime value.
VarFromDateTime is a real function.
Tips and Tricks
You must call
VarFromDateTimeto convert aTDateTimevalue to aVariant. If you try to assign aTDateTimeto aVariant, Delphi creates avarDoubleVariantbecauseTDateTimeis really a floating-point type.Delphi’s format for
TDateTimevalues is the OLE standard, so if you create avarDateVariantby directly assigning the member of aTVarDatarecord, you can assign aTDateTimevalue to theVDatemember.If you want extra control over the string formatting of a
TDateTime, you can callVarToDateTimeand then use the functions inSysUtilsto format the string. Casting thevarDateto avarStringvalue always uses a short date and time format.
Example
// The following two examples do the same thing.
V := VarFromDateTime(Now);
VarClear(V);
TVarData(V).VType := varDate;
TVarData(V).VDate := Now;See Also
| TDateTime Type, VarClear Procedure, Variant Type, VarToDateTime Function |
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