CToD Function (String) | |
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
) AS DATE
public static Date CToD(
string cDate
)
Request Example
View SourceParameters
- 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().
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:
This example compares the return value of CToD() with a hard-coded date:
1? CToD("05/15/64") = 64.05.15
This example shows that a declared strongly typed DATE variable is initialized to an empty date:
1LOCAL dInit AS DATE
2? CToD(NULL_STRING) = dInit
3? CToD(NULL_STRING) = NULL_DATE
This example demonstrates the inverse relationship between CToD() and DToC():
1? CToD(DToC(Today())) = Today()
See Also