Share via


DATETIME( ) Function

Returns the current date and time as a DateTime value, or creates a year 2000-compliant DateTime value.

DATETIME([nYear, nMonth, nDay [, nHours [, nMinutes [, nSeconds]]]])

Return Value

DateTime

Parameters

  • nYear
    Specifies the year returned in the year 2000-compliant DateTime value. nYear can be a value from 100 to 9999.

  • nMonth
    Specifies the month returned in the year 2000-compliant DateTime value. nMonth can be a value from 1 to 12.

  • nDay
    Specifies the day returned in the year 2000-compliant DateTime value. nDay can be a value from 1 to 31.

  • nHours
    Specifies the hours returned in the year 2000-compliant DateTime value. nHours can be a value from 0 (midnight) to 23 (11 P.M). Defaults to 0 if omitted.

  • nMinutes
    Specifies the minutes returned in the year 2000-compliant DateTime value. nMinutes can be a value from 0 to 59. Defaults to 0 if omitted.

  • nSeconds
    Specifies the seconds returned in the year 2000-compliant DateTime value. nSeconds can be a value from 0 to 59. Defaults to 0 if omitted.

Remarks

DATETIME( ) returns the current system DateTime if it is issued without the optional arguments. Any NULL date parameters are replaced with current system values. A NULL time parameter is replaced with 12:00:00.

Include the optional arguments to return a year 2000-compliant DateTime value in the format specified in the Regional tab of the Options dialog box.

Example

This first example stores the Datetime for the New Year to a variable named tNewyear, and stores the current Datetime to a variable named tToday. The number of seconds between the current Datetime and the New Year is then displayed.

The second example uses DATETIME( ) to create a year 2000-compliant DateTime value.

tNewyear = DATETIME(YEAR(DATE( ) ) + 1, 1, 1)  && Next New Year
tToday = DATETIME( )
nSecondstonewyear = tNewyear - tToday
CLEAR
? "There are " + ALLTRIM (STR(nSecondstonewyear)) ;
   + " seconds to the next New Year."

CLEAR
SET CENTURY ON
SET DATE TO AMERICAN
? DATETIME(1998, 02, 16, 12, 34, 56) && Displays 02/16/1998 12:34:56 PM

See Also

Reference

CTOT( ) Function

DATE( ) Function

DTOT( ) Function

HOUR( ) Function

SEC( ) Function

SECONDS( ) Function

SET SECONDS Command

SET SYSFORMATS Command

TIME( ) Function

TTOC( ) Function

TTOD( ) Function

Other Resources

Functions

Language Reference (Visual FoxPro)