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 a TDateTime variable does not work. Because TDateTime is a floating-point type, the assignment would try to convert the Variant to a varDouble, not a varDate.

  • VarToDateTime eventually calls the Windows API function VariantChangeTypeEx to parse the string and interpret the date and time. See the Platform SDK documentation for details. VarToDateTime accepts many more formats than StrToDateTime.

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
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset