INFORMIX
Informix-ESQL/C Programmer's Manual
Chapter 6: Working with Time Data Types
Home Contents Index Master Index New Book

DATE Library Functions

The following date-manipulation functions are in the ESQL/C library. They convert dates between a string format and the internal DATE format.

Function Name Description

rdatestr()

Converts an internal DATE to a character string format

rdayofweek()

Returns the day of the week of a date in internal format

rdefmtdate()

Converts a specified string format to an internal DATE

rfmtdate()

Converts an internal DATE to a specified string format

rjulmdy()

Returns month, day, and year from an internal DATE

rleapyear()

Determines whether specified year is a leap year

rmdyjul()

Returns an internal DATE from month, day, and year

rstrdate()

Converts a character string format to an internal DATE

rtoday()

Returns a system date as an internal DATE

When you compile your ESQL/C program with the esql command, esql automatically links these functions into your program. The following pages describe each of these functions.

rdatestr()

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

Syntax

Usage

For the default locale, U.S. English, the rdatestr() function determines how to interpret the format of the character string with the following precedence:

1. The format that the DBDATE environment variable specifies (if DBDATE is set). For more information on DBDATE, refer to the Informix Guide to SQL: Reference.

    GLS
    2. The format that the GL_DATE environment variable specifies (if GL_DATE is set). For more information on GL_DATE, refer to the
    Informix Guide to GLS Functionality.

    3. The default date form: mm/dd/yyyy.

GLS
When you use a nondefault locale and do not set the DBDATE or GL_DATE environment variable, rdatestr() uses the date end-user format that the client locale defines. For more information, see the
Informix Guide to GLS Functionality.

Return Codes

0

The conversion was successful.

<0

The conversion failed.

-1210

The internal date could not be converted to the character string format.

-1212

Data conversion format must contain a month, day, or year component. DBDATE specifies the data conversion format.

Example

The demo directory contains this sample program in the rtoday.ec file.

Example Output

rdayofweek()

The rdayofweek() function returns the day of the week as an integer value for an internal DATE.

Syntax

Return Codes

0

Sunday

1

Monday

2

Tuesday

3

Wednesday

4

Thursday

5

Friday

6

Saturday

Example

The demo directory contains this sample program in the rdayofweek.ec file.

Example Output

rdefmtdate()

The rdefmtdate() function uses a formatting mask to convert a character string to an internal DATE format.

Syntax

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 on these date formats, see "Formatting 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. The following combinations of fmtstring and input are valid.

(1 of 2)

Formatting Mask Input

mmddyy

Dec. 25th, 1995

mmm. dd. yyyy

dec 25 1995

mmm. dd. yyyy

DEC-25-1995

mmm. dd. yyyy

122595

mmm. dd. yyyy

12/25/95

yy/mm/dd

95/12/25

yy/mm/dd

1995, December 25th

yy/mm/dd

In the year 1995, the month of December, it is the 25th day

dd-mm-yy

This 25th day of December, 1995

When you use a two-digit year (yy) in a format, the rdefmtdate() function uses the value of the DBCENTURY environment variable to determine which century to use. If you do not set DBCENTURY, ESQL/C uses the 20th century. For information on how to set DBCENTURY, see the Informix Guide to SQL: Reference.

GLS
When you use a nondefault locale whose dates contain eras, you can use extended-format strings in the fmtstring argument of rdefmtdate(). For more information, see the
Informix Guide to GLS Functionality.

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 six or eight bytes.

-1212

*fmtstring does not specify a year, a month, and a day.

Example

The demo directory contains this sample program in the rdefmtdate.ec file.

Example Output

rfmtdate()

The rfmtdate() function uses a formatting mask to convert an internal DATE format to a character string.

Syntax

Usage

The fmtstring argument of the rfmtdate() function points to the date-formatting mask, which contains formats that describe how to format the date string. For more information on these date formats, see "Formatting Date Strings".

The examples in the following table use the formatting mask in fmtstring to convert the integer jdate, whose value corresponds to December 25, 1995, to a formatted string outbuf.

(1 of 2)

Formatting Mask Formatted Result

"mmddyy"

122595

"ddmmyy"

251295

"yymmdd"

951225

"yy/mm/dd"

95/12/25

"yy mm dd"

95 12 25

"yy-mm-dd"

95-12-25

"mmm. dd, yyyy"

Dec. 25, 1995

"mmm dd yyyy"

Dec 25 1995

"yyyy dd mm"

1995 25 12

"mmm dd yyyy"

Dec 25 1995

"ddd, mmm. dd, yyyy"

Mon, Dec. 25, 1995

"(ddd) mmm. dd, yyyy"

(Mon) Dec. 25, 1995

GLS
When you use a nondefault locale whose dates contain eras, you can use extended-format strings in the fmtstring argument of rfmtdate(). For more information, see the
Informix Guide to GLS Functionality.

Return Codes

0

The conversion was successful.

-1210

The internal date cannot be converted to month-day-year format.

-1211

The program ran out of memory (memory-allocation error).

Example

The demo directory contains this sample program in the rfmtdate.ec file.

Example Output

rjulmdy()

The rjulmdy() function creates an array of three short integer values that represent the month, day, and year from an internal DATE value.

Syntax

Return Codes

0

The operation was successful.

< 0

The operation failed.

-1210

The internal date could not be converted to the character string format.

Example

The demo directory contains this sample program in the rjulmdy.ec file.

Example Output

rleapyear()

The rleapyear() function returns 1 (TRUE) when the argument that is passed to it is a leap year and 0 (FALSE) when it is not.

Syntax

Usage

The argument year must be the year component of a date and not the date itself. You must express the year in full form (1996) and not abbreviated form (96).

Return Codes

1

The year is a leap year.

0

The year is not a leap year.

Example

The demo directory contains this sample program in the rleapyear.ec file.

Example Output

rmdyjul()

The rmdyjul() function creates an internal DATE from an array of three short integer values that represent month, day, and year.

Syntax

Usage

You can express the year in full form (1996) or abbreviated form (96).

Return Codes

0

The operation was successful.

-1204

The mdy[2] variable contains an invalid year.

-1205

The mdy[0] variable contains an invalid month.

-1206

The mdy[1] variable contains an invalid day.

Example

The demo directory contains this sample program in the rmdyjul.ec file.

Example Output

rstrdate()

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

Syntax

Usage

For the default locale, U.S. 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 on DBDATE, refer to the Informix Guide to SQL: Reference.

    GLS
    2. The format that the GL_DATE environment variable specifies (if GL_DATE is set). For more information on GL_DATE, refer to the
    Informix Guide to GLS Functionality.

    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 (1995) or as two digits (95).

GLS
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
Informix Guide to GLS Functionality.

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 on how to set DBCENTURY, see the Informix 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.

Example Output

rtoday()

The rtoday() function returns the system date as an internal DATE value.

Syntax

Usage

The rtoday() function obtains the system date on the client computer, not the server computer.

Example

The demo directory contains this sample program in the rtoday.ec file.

Example Output




Informix-ESQL/C Programmer's Manual, version 9.1
Copyright © 1998, Informix Software, Inc. All rights reserved.