Click or drag to resize

CToD Function (String, String)

X#
Convert a date string to date format.

Namespace:  XSharp.RT
Assembly:  XSharp.RT (in XSharp.RT.dll) Version: 2.19
Syntax
 FUNCTION CToD(
	cDate AS STRING,
	cDateFormat AS STRING
) AS DATE
Request Example View Source

Parameters

cDate
Type: String
A string of numbers representing the month, day, and year, separated by any character other than a number. The month, day, and year digits must be in the format set by SetDateFormat() or SetDateCountry(). If the century digits are not specified, the century is determined by the rules of SetEpoch().
cDateFormat
Type: String
A string representating the date format to use when converting the string to a date. Should consist of D, M and Y characters and separators.

Return Value

Type: Date
The date value that corresponds to the numbers specified in cDate.
If cDate is not a valid date, CToD() returns a NULL_DATE.
Remarks
CToD() is a character conversion function that converts a date value originally formatted as a string to a date data type.
To initialize a NULL_DATE, specify cDate as a NULL_STRING. Keep in mind, however, that you can obtain empty date (or even non-empty dates), without incurring a function call overhead, by just specifying a date literal such as 92.07.22.
Moreover , when a strongly typed variable is declared as having the DATE type, it is automatically initialized to an empty date. CToD() is the inverse of DToC(), which converts a date value to a string.
DToS() also converts a date value to a string, and, since it is in the form of yyyymmdd, it is usually the preferred form for indexing a date in combination with a string.
Examples
This example simply applies CToD() to a string:
X#
1? CToD("05/15/64")                    // 05/15/64
This example compares the return value of CToD() with a hard-coded date:
X#
1? CToD("05/15/64") = 64.05.15        // .T.
This example shows that a declared strongly typed DATE variable is initialized to an empty date:
X#
1LOCAL dInit AS DATE
2? CToD(NULL_STRING) = dInit            // .T.
3? CToD(NULL_STRING) = NULL_DATE        // .T.
This example demonstrates the inverse relationship between CToD() and DToC():
X#
1? CToD(DToC(Today())) = Today()        // .T.
See Also