Partager via


TTOC( ) Function

Converts a DateTime expression to a Character value with the specified format.

TTOC(tExpression [, 1 | 2 | 3])

Parameters

  • tExpression
    Specifies a DateTime expression to convert into a character string.

    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 a default time of 12:00:00 AM (if SET HOURS is 12) or 00:00:00 (if SET HOURS is 24) to tExpression to produce a valid DateTime value.

  • 1
    Returns tExpression as a character string in a format suitable for indexing. The character string returned has a 14-character format, yyyymmddhhmmss, that is not affected by the SET CENTURY, the SET HOURS, or SET SECONDS commands. For more information, see SET CENTURY, SET HOURS, and SET SECONDS.

  • 2
    Returns tExpression as a character string containing only the time portion of tExpression.

    To control whether to include the seconds of the time portion in the character string, set the SET SECONDS and SET DATE commands. The SET HOURS command determines if AM or PM is appended to the time portion returned.

    For more information, see SET DATE and SET HOURS.

    Note

    If SET DATE is set to LONG or SHORT, the format of the time setting in the Windows Control Panel determines the format of the character string.

  • 3
    Returns tExpression as a character string with the XML DateTime format. The character string returned has a 19-character yyyy-mm-ddThh:mm:ss format that is not affected by the settings of the SET CENTURY, SET HOURS, or SET SECONDS commands.

Return Value

Character. TTOC( ) returns a DateTime expression as a character string.

Note

When passing the value 1 or 3 as the second parameter, the character string returned does not include the AM or PM designations to indicate times before or after noon, respectively. Instead, the string uses a 24-hour clock, also known as military time. For example, the time 18:30:00 is equivalent to 06:30:00 PM.

Remarks

If an invalid value is passed as the second parameter, TTOC( ) handles the invalid value as if it was a value of 1.

Example

The following example converts a DateTime value to a Character value. The STORE command stores the results of the DATETIME( ) function, which returns the current date and time as a DateTime value, to a variable named gtDateTime. The ? command displays text and the results of the TYPE( ) function, which returns the letter T as the type of the gtDateTime variable. The TTOC( ) function converts gtDateTime to a character string, and the TYPE( ) functions returns the letter T as the current type of gtDateTime.

STORE DATETIME( ) TO gtDateTime  
? "gtDateTime has type: "+TYPE('gtDateTime') 
gtDateTime = TTOC(gtDateTime)     
? "gtDateTime is now type: "+TYPE('gtDateTime')

See Also

Reference

DateTime Data Type

Character Data Type

DATE( ) Function

DATETIME( ) Function

HOUR( ) Function

MINUTE( ) Function

SEC( ) Function

SECONDS( ) Function

SET HOURS Command

SET DATE Command

TIME( ) Function

TTOD( ) Function

Other Resources

Functions

Language Reference (Visual FoxPro)