VariantsVarToDateTime (C++)

From RAD Studio Code Examples
Jump to: navigation, search

Description

This example demonstrates the use of the VarToDateTime function in the Variants unit.

Code

int _tmain(int argc, _TCHAR* argv[])
{
  TDateTime ldate;
  Variant vdatestring;
  char str[50] = {0};

  // Wait for user input. 
  printf("Write an input date/time (MM/DD/YYYY): "); scanf("%s", &str);

  // Assign the string to a Variant.
  vdatestring = str;

  try
  {
	  // Convert the preassigned Variant to TDateTime.
	  ldate = VarToDateTime(vdatestring);

	  // Write the value to the console.
	  printf("%ls", DateTimeToStr(ldate));
	  Sleep(3000);
  }
  catch(EVariantTypeCastError* e)
  {
	  printf("Invalid date/time string supplied!\n");
	  return -1;
  }
}

Uses

Personal tools
Assistance