Functions and Directives

Function CtoD() Foundation

Converts a date character string to a date value.

CtoD( <cDate> ) --> dDate
<cDate> is a character string in the format of a date value. It consists of numbers for month, day and year which are separated by a character which is not a number. The numbers for month, day and year must be in the same order as in the date format set with SET DATE.
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.

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


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

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(). DtoC() converts date values to character strings in a format dependent on the settings defined with SET DATE and SET CENTURY.

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.

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 


   SET DATE GERMAN                 // select German date format 

   ? CMonth( CtoD( "12.06.94" ) )  // result: June 

   SET DATE AMERICAN               // select US date format 

   ? CMonth( CtoD( "12/06/94" ) )  // result:December 


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. 

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

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

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



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.