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 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.

Remember that the VFP 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 DateTime. Note that CTOT() will fail if STRICTDATE is set to 2.
DATE() return today's date in the format specified by SET DATE and SET CENTURY.
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 of characters 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 DateTime with the time set to 12:00:00 am.
GOMONTH(<date>, <n>) return a date <n> months after <date>. The VFP GOMONTH function makes sensible decisions about the calendar. For example, it returns Feb 28th (or 29th in a Leap Year) as being one month after Jan 31st rather than trying to set Feb 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 rather than as numeric. Use the SECONDS function if you are needing to do arithmetic with the value, use SYS(2) if you are using it for something like a temporary file name.
SET CENTURY ON|OFF show or hide the century digits when dates are displayed. Note that VFP still stores the century information 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 an unusual {^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. Note that the VFP function SECONDS() gives it as a number with three decimal places. Use the SECONDS function if you are needing to do arithmetic with the value, use SYS(2) if you are using it for something like a temporary file name.
TIME() return the current time as an eight-character string "hh:mm:ss".

Access Tips

FoxPro Tips

General Tips

 

Related Items

Alvechurch Data - Microsoft FoxPro and Access Database Development and Training

Alvechurch Data are based close to Birmingham and provide Microsoft Access and Visual FoxPro training, development and support.

Read More

Autocomplete in Visual Fox Pro

Visual Fox Pro textbox with autocomplete.

The VFP textbox class in version 9 has a new Autocomplete property which shows the user the previous values that have been entered into that textbox.

Read More

FoxPro Functions

FoxPro has always had functions like FREAD and FWRITE to read and write binary files at a low level. They can handle files which defeat the STRTOFILE and FILETOSTR functions for text files.

Read More

Development Services

Alvechurch Data are based in Worcestershire and specialise in Microsoft Access and Visual FoxPro databases. They have fifteen years experience developing systems for small business use.

Read More

Access and Visual FoxPro Training

Microsoft Visual FoxPro and Access training. Courses and workshops from Alvechurch Data in Worcestershire and the West Midlands.

Read More