Dates can be stored as separate integers for the day, month, and year. To convert a date string to its integer components, use the date to numbers function, date_tonums():
|
||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Pointers to the variables to place the date's components must be passed.
The date string is broken into the three sub-strings defined by the format string. Each of these is converted to an integer value and checked that it is the valid range for that component. If the month is a string, it is converted to the appropriate number. Days are checked to make sure it is a valid number based on the given month. Leap years are taken into account. The integers are copied to the variables specified in the call.
To convert the integer components of a date into a date string, call the date from numbers function, date_frnums():
|
||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Based on the format string, a date string is created from the integer components of the date. If the format calls for a month in string format, the month is used as an index into the array of month strings.
Note that you must allocate memory for the string used to receive the formatted date. This string must be long enough to accept a date string of the specified format.