Function CtoD() Foundation

Converts a date character string to a date value.

Syntax
CtoD( <cDate>[, <cDateFormat>] ) --> dDate
Parameters
<cDate>
<cDate> is a character string specifying a date value. Typically, the string consists of numbers for month, day and year which are separated by a character which is not a number. The exact format of the character string depends on the selected date format.
When the numbers for the century are missing from the character string, or when the string represents a numeric value of less than 100, the character string is interpreted according to the rules set by the command SET EPOCH.
<cDateFormat>
The optional parameter <cDateFormat> is a character string specifying the format of the date string assigned to <cDate>. By default, this is the current date format set via SET DATE.
Return

CtoD() returns a date value. When <cDate> is an invalid date, CtoD() returns an empty date.

Description

CtoD() converts a character string to a date value. Date values can only be created using CtoD(), StoD() and Date(). To create an empty date value (such as to prepare for date input), a null string (""), Space(8), or " / / " must be passed as <cDate> to CtoD(). Note that the exact format of the character string and the delimiters contained in the string depends on the date format selected via the<cDateFormat> parameter.

CtoD() is used when literal date values must be converted to a date value in a program. The counterpart function DtoC() reverses the function CtoD().

When character strings and date values are combined in an index key, the function DtoC() should not be used. The function DtoS(), which also converts date values to a character string, should be used instead. DtoS() returns the character string in the format YYYYMMDD as required for correct sorting.

Examples
The significance of SET DATE for CtoD()

// The example demonstrates the result of the conversion of a 
// character string to a date value dependent on SET DATE 

PROCEDURE Main 

   // Select German date format 
   SET DATE GERMAN 

   ? CMonth( CtoD( "12.06.94" ) )             // -> "June" 

   ? CMonth( CtoD( "06/12/94", "mm/dd/yy" ) ) // -> "June" 

   // Select US date format 
   SET DATE AMERICAN 

   ? CMonth( CtoD( "12/06/94" ) )             // -> "December" 

RETURN 

Input date values with GET

// In the example, two variables are initialized 
// with the function CtoD() to an empty date value 
// prior to editing in two GET fields. 

PROCEDURE Main 
   dArrival   := CtoD("") 
   dDeparture := CtoD("") 

   @ 10, 10 SAY  "Arrival:" GET dArrival ; 
            RANGE Date() ,  Date()+365 

   @ 12, 10 SAY   "Departure:" GET dDeparture ; 
            RANGE dArrival , dArrival+365 

   READ 

RETURN 
Feedback

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.