CToD Function (String, String)
Convert a date string to date format.
XSharp.RT (in XSharp.RT.dll) Version: 2.2a
Syntax View Source
cDate AS STRING,
cDateFormat AS STRING
) AS DATE
public static Date CToD(
- 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().
- 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.
The date value that corresponds to the numbers specified in <cDate>. If <cDate> is not a valid date, CToD() returns a NULL_DATE.
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.
This example simply applies CToD() to a string:
? CToD("05/15/64") // 05/15/64
This example compares the return value of CToD() with a hard-coded date:
? CToD("05/15/64") = 64.05.15 // .T.
This example shows that a declared strongly typed DATE variable is initialized to an empty date:
LOCAL dInit AS DATE
? CToD(NULL_STRING) = dInit // .T.
? CToD(NULL_STRING) = NULL_DATE // .T.
This example demonstrates the inverse relationship between CToD() and DToC():
? CToD(DToC(Today())) = Today() // .T.