JavaScript Editor js editor     Web development 

Main Page

Returns a DateTime value from a character expression.




Specifies the character expression from which a DateTime value is returned.

Return Value

DateTime data type. CTOT( ) returns a DateTime value from a character expression.


CTOT() can create ambiguous DateTime values and generates a compilation error when SET STRICTDATE is set to 2. To create nonambiguous Date values, use the DATETIME(В ) function instead.

Visual FoxPro supports the native SQL Datatypes Datetime and Smalldatetime, which are returned in 24 hour format in SQL XML.

The CTOT() function does not address the 19 different ways that T-SQL Convert() function returns datetime and smalldatetime values.

To convert date formats from Access, SQL Server, Visual Studio, and XML, you must call the appropriate SET DATE setting to interpret DateTime strings properly. However, if an uppercase T is in the XML date string, Visual FoxPro overrides the current date setting by internally calling SET DATE YMD and restores the current date setting when exiting CTOT(В ).

CTOT( ) resolves these dates to the limits of precision of the Visual FoxPro DateTime data type. Therefore, precision can be lost when using CTOT( ) with certain formats. The Visual FoxPro DateTime data type does not support milliseconds or time zones.

CTOT( ) respects the setting of the SET CENTURY command. For more information, see SET CENTURY Command.


The following examples show how CTOT(В ) handles DateTime values from different sources. In all examples, CTOT(В ) converts the DateTime values correctly without needing to call SET DATE YMD.

  • Access 2000 XML date format

    В Copy Code
    * 2000-10-24T13:30:00 (24-hour format is exported from Access,
    * whether original was in 12- or 24-hour format)
    ? CTOT("2000-10-24T13:30:00")
  • SQL Server 2000 XML date format

    В Copy Code
    ? CTOT("2000-10-24T20:47:58.170")   && datetime (24-hour format)
    ? CTOT("2000-10-24T21:11:00")         && Small DT (24-hour format)
    ? CTOT("2000-10-03T02:02:02")
  • Visual Studio XML

    В Copy Code
    ? CTOT("2002-10-05T04:04:04.0000000-07:00")
  • Simple Object Access Protocol (SOAP)

    В Copy Code
    ? CTOT("2001-09-14T07:00:00Z")

See Also

JavaScript Editor js editor     Web development