The rdefmtdate() function
The rdefmtdate() function uses a formatting mask to convert a character string to an internal DATE format.
Syntax
mint rdefmtdate(jdate, fmtstring, inbuf)
int4 *jdate;
char *fmtstring;
char *inbuf;
- jdate
- A pointer to a int4 integer value that receives the internal DATE value for the inbuf string.
- fmtstring
- A pointer to the buffer that contains the formatting mask to use the inbuf string.
- inbuf
- A pointer to the buffer that contains the date string to convert.
Usage
The fmtstring argument of the rdefmtdate() function points to the date-formatting mask, which contains formats that describe how to interpret the date string. For more information about these date formats, see Format date strings
The input string and the fmtstring must be in the same sequential order in terms of month, day, and year. They need not, however, contain the same literals or the same representation for month, day, and year.
You
can include the weekday format (ww
), in fmtstring,
but the database server ignores that format. Nothing from the inbuf corresponds
to the weekday format.
The following combinations of fmtstring and input are valid.
- Formatting mask
- Input
- mmddyy
- Dec. 25th, 2007
- mmddyyyy
- Dec. 25th, 2007
- mmm. dd. yyyy
- dec 25 2007
- mmm. dd. yyyy
- DEC-25-2007
- mmm. dd. yyyy
- 122507
- mmm. dd. yyyy
- 12/25/07
- yy/mm/dd
- 07/12/25
- yy/mm/dd
- 2007, December 25
- yy/mm/dd
- In the year 2007, the month of December, it is the 25th day
- dd-mm-yy
- This 25th day of December 2007
If the value stored in inbuf is a four-digit year, the rdefmtdate() function uses that value. If the value stored in inbuf is a two-digit year, the rdefmtdate() function uses the value of the DBCENTURY environment variable to determine which century to use. If you do not set DBCENTURY, Informix® ESQL/C uses the 20th century. For information about how to set DBCENTURY, see the Informix® Guide to SQL: Reference.
Return codes
- 0
- The operation was successful.
- -1204
- The *input parameter specifies an invalid year.
- -1205
- The *input parameter specifies an invalid month.
- -1206
- The *input parameter specifies an invalid day.
- -1209
- Because *input does not contain delimiters between the year, month, and day, the length of *input must be exactly 6 or 8 bytes.
- -1212
- *fmtstring does not specify a year, a month, and a day.
Example
/*
* rdefmtdate.ec *
The following program accepts a date entered from the console,
converts it into the internal date format using rdefmtdate().
It checks the conversion by finding the day of the week.
*/
#include <stdio.h>
main()
{
mint x;
char date[20];
int4 i_date;
char *day_name;
static char fmtstr[9] = "mmddyyyy";
printf("RDEFMTDATE Sample ESQL Program running.\n\n");
printf("Enter a date as a single string, month.day.year\n");
gets(date);
printf("\nThe date string is %s.\n", date);
if (x = rdefmtdate(&i_date, fmtstr, date))
printf("Error %d on rdefmtdate conversion\n", x);
else
{
/* Figure out what day of the week i_date is */
switch (rdayofweek(i_date))
{
case 0: day_name = "Sunday";
break;
case 1: day_name = "Monday";
break;
case 2: day_name = "Tuesday";
break;
case 3: day_name = "Wednesday";
break;
case 4: day_name = "Thursday";
break;
case 5: day_name = "Friday";
break;
case 6: day_name = "Saturday";
break;
}
printf("\nThe day of the week is %s.\n", day_name);
}
printf("\nRDEFMTDATE Sample Program over.\n\n");
}
Output
RDEFMTDATE Sample ESQL Program running.
Enter a date as a single string, month.day.year
080894
The date string is 080894
The day of the week is Monday.
RDEFMTDATE Sample Program over.