Converting Dates From and To Their Integer Components

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

int date_tonums(date_stp, dayp, monthp, yearp, format_stp)
 
UCHAR *date_stp;
/* Date string to convert
*/
int *dayp;
/* Pointer to variable to place days
*/
int *monthp;    
/* Pointer to variable to place month
*/
int *yearp;
/* Pointer to variable to place year
*/
UCHAR *format_stp;
/* Date format string to use
*/

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

int date_frnums(date_stp, day, month, year, format_stp)
 
UCHAR *date_stp;
/* Date string to place formatted date
*/
int day;
/* Number of days
*/
int month;
/* Number of month
*/
int year;
/* Year
*/
UCHAR *format_stp;
/* Date format string to use
*/

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.


Home Contents Previous Next