Visual FoxPro Date Functions

FoxPro is very good at processing dates and can handle values between Jan 1st 0001 and Dec 31st 9999. All Leap Years - including the century values - are treated correctly. Its only real weakness is that it still includes the 11 days dropped on the changeover between Julian and Gregorian calendars in 1752. Look in the FoxPro Help system for more information about the syntax and use of these functions.

FoxPro syntax requires that functions are always followed by a pair of brackets even if - as with the DATE() function - there's nothing in them.

CDOW(<date>) return the name of the day of the week of <date>.
CMONTH(<date>) return the name of the month of <date>.
CTOD(<text>) return <text> as a variable of type Date. Note that CTOD() will fail if STRICTDATE is set to 2.
CTOT(<text>) return <text> as a variable of type DateTime. Note that CTOT() will fail if STRICTDATE is set to 2.
DATE() return today's date.
DATE(<yyyy>,<mm>,<dd>) return a date variable holding dd/mm/yyyy. Use this function in place of CTOD() when STRICTDATE is set to 2
DMY(<date>) return <date> in full as a string variable such as "25 December 2007".
DOW(<date>) return the day of the week of <date> as a number with Sunday counting as Day 1.
DTOC(<date>) return <date> as a variable of type string in 'dd/mm/yy' or 'dd/mm/yyyy' format depending on the state of SET CENTURY and SET DATE.
DTOS(<date>) return <date> as a variable of type string in 'yyyymmdd' format. The year will include the century digits regardless of the state of SET CENTURY Use DTOS() when you are wanting to index on a composite expression such as Surname + DTOS(DateOfBirth).
DTOT(<date>) return <date> as a variable of type DateTime with the time set to 12:00:00 am.
GOMONTH(<date>, <n>) return a date <n> months after <date>. GOMONTH makes sensible decisions about the calendar. It returns Feb 28th (or 29th in a Leap Year) as being one month after Jan 31st.
MONTH(<date>) return the month of <date> as a number between 1 and 12.
SECONDS() return the number of seconds since midnight. Given with three decimal places but not guaranteed to that accuracy. SYS(2) gives a similar value as text.
SET CENTURY ON|OFF show or hide the century digits when dates are displayed. Note that the century information is still stored whether CENTURY is ON or OFF.
SET CENTURY TO <cc> ROLLOVER <yy> set a 100-year window for years entered as two digits. Years after the <yy> limit will be treated as belonging to the century specified as <cc>. Years before that point will be treated as belonging to the next century.
SET DATE set the format for displaying dates. For example SET DATE BRITISH.
SET STRICTDATE TO 0|1|2 restrict the formatting of dates. A value of 1 or 2 forces you to enter dates in a strict {^yyyy-mm-dd} format. A value of 2 also prevents you using the CTOD() or CTOT() functions at all.
SYS(2) return the number of whole seconds since midnight as text. SECONDS() gives it as a number with three decimal places.
TIME() return the current time as an eight-character string "hh:mm:ss".