Share via


TTOC( ) Function

Converts a DateTime expression to a Character value of a specified format.

TTOC(tExpression [, 1 | 2])

Return Values

Character

Parameters

  • tExpression
    Specifies a DateTime expression from which TTOC( ) returns a Character value. If tExpression contains only a time, Visual FoxPro adds the default date of 12/30/1899 to tExpression. If tExpression contains only a date, Visual FoxPro adds the default time of midnight (12:00:00 A.M.) to tExpression.
  • 1
    Specifies that TTOC( ) return a Character string in a format suitable for indexing. The character string has a 14 character yyyy:mm:dd:hh:mm:ss format that is not affected by the current settings of SET CENTURY or SET SECONDS.
  • 2
    Specifies that TTOC( ) return a Character string consisting of only the time portion of the DateTime expression. The settings of SET SECONDS and SET DATE specify if the seconds portion of the time is included in the character string. Note that if SET DATE is set to LONG or SHORT, the format of the character string is determined by the format of the Control Panel time setting.

Example

The following example creates a Datetime type variable named gtDtime. TYPE( ) displays T, indicating the variable is a Datetime type. TTOC( ) is used to convert the variable to a character type, and TYPE( ) now displays C, indicating the variable is a character type after the conversion.

STORE DATETIME( ) TO gtDtime  && Creates a Datetime type memory variable
CLEAR
? "gtDtime is type: "  
?? TYPE('gtDtime')  && Displays T, Datetime type value

gtDtime = TTOC(gtDtime)     &&  Converts gtDtime to a character value
? "gtDtime is now type: "  
?? TYPE('gtDtime')  && Displays C, character type value

See Also

DATE( ) | DATETIME( ) | HOUR( ) | MINUTE( ) | SEC( ) | SECONDS( ) | SET CENTURY | SET DATE,SET SECONDS | TIME( ) | TTOD( )