The rstrdate() function

The rstrdate() function converts a character string to an internal DATE.

Syntax

mint rstrdate(inbuf, jdate)
   char *inbuf;
   int4 *jdate;
inbuf
A pointer to the string that contains the date to convert.
jdate
A pointer to an int4 integer that receives the internal DATE value for the inbuf string.

Usage

For the default locale, US English, the rstrdate() function determines how to format the character string with the following precedence:
  1. The format that the DBDATE environment variable specifies (if DBDATE is set). For more information about DBDATE, see the HCL OneDB™ Guide to SQL: Reference.
  2. The format that the GL_DATE environment variable specifies (if GL_DATE is set). For more information about GL_DATE, see the HCL OneDB GLS User's Guide.
  3. The default date form: mm/dd/yyyy. You can use any nonnumeric character as a separator between the month, day, and year. You can express the year as four digits (2007) or as two digits (07).

When you use a nondefault locale and do not set the DBDATE or GL_DATE environment variable, rstrdate() uses the date end-user format that the client locale defines. For more information, see the HCL OneDB GLS User's Guide.

When you use a two-digit year in the date string, the rstrdate() function uses the value of the DBCENTURY environment variable to determine which century to use. If you do not set DBCENTURY, rstrdate() assumes the 20th century for two-digit years. For information about how to set DBCENTURY, see the HCL OneDB Guide to SQL: Reference.

Return codes

0
The conversion was successful.
< 0
The conversion failed.
-1204
The inbuf parameter specifies an invalid year.
-1205
The inbuf parameter specifies an invalid month.
-1206
The inbuf parameter specifies an invalid day.
-1212
Data conversion format must contain a month, day, or year component. DBDATE specifies the data conversion format.
-1218
The date specified by the inbuf argument does not properly represent a date.

Example

The demo directory contains this sample program in the rstrdate.ec file.
/*
   * rstrdate.ec *
   The following program converts a character string
   in "mmddyyyy" format to an internal date format.
*/

#include <stdio.h>

main()
{
    int4 i_date;
    mint errnum;
    char str_date[15];

    printf("RSTRDATE Sample ESQL Program running.\n\n");

    /* Convert Sept. 6th, 2007 into i_date */
    if ((errnum = rstrdate("9.6.2007", &i_date)) == 0)
      {

      rfmtdate(i_date, "mmm dd yyyy", str_date);
      printf("Date '%s' converted to internal format\n" str_date);
      }
    else
      printf("rstrdate() call failed with error %d\n", errnum);

    printf("\nRSTRDATE Sample Program over.\n\n");
}

Output

RSTRDATE Sample ESQL Program running.

Date 'Sep 06 2007' converted to internal format

RSTRDATE Sample Program over.