The dtcvasc() function

The dtcvasc() function converts a string that conforms to ANSI SQL standard for a DATETIME value to a datetime value.

For information about the ANSI SQL DATETIME standard, see ANSI SQL standards for DATETIME and INTERVAL values.

Syntax

mint dtcvasc(inbuf, dtvalue)
   char *inbuf;
   dtime_t *dtvalue;
inbuf
A pointer to the buffer that contains an ANSI-standard DATETIME string.
dtvalue
A pointer to an initialized datetime variable.

Usage

You must initialize the datetime variable in dtvalue with the qualifier that you want this variable to have.

The character string in inbuf must have values that conform to the year to second qualifier in the ANSI SQL format. The inbuf string can have leading and trailing spaces. However, from the first significant digit to the last, inbuf can only contain characters that are digits and delimiters that conform to the ANSI SQL standard for DATETIME values.

If you specify a year value as one or two digits, the dtcvasc() function assumes that the year is in the present century. You can set the DBCENTURY environment variable to determine which century dtcvasc() uses when you omit a century from the date.

If the character string is an empty string, the dtcvasc() function sets to null the value to which dtvalue points. If the character string is acceptable, the function sets the value in the datetime variable and returns zero. Otherwise, the function leaves the variable unchanged and returns a negative error code.

Return codes

0
Conversion was successful.
-1260
It is not possible to convert between the specified types.
-1261
Too many digits in the first field of datetime or interval.
-1262
Non-numeric character in datetime or interval.
-1263
A field in a datetime or interval value is out of range or incorrect.
-1264
Extra characters exist at the end of a datetime or interval.
-1265
Overflow occurred on a datetime or interval operation.
-1266
A datetime or interval value is incompatible with the operation.
-1267
The result of a datetime computation is out of range.
-1268
A parameter contains an invalid datetime qualifier.

Example

The demo directory contains this sample program in the dtcvasc.ec file.
/*
   * dtcvasc.ec *

   The following program converts ASCII datetime strings in ANSI SQL format
   into datetime (dtime_t) structure.
*/

#include <stdio.h>

EXEC SQL include datetime;

main()
{
    mint x;

    EXEC SQL BEGIN DECLARE SECTION;
      datetime year to second dt1;
    EXEC SQL END DECLARE SECTION;

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

    printf("Datetime string #1 = 2007-02-11 3:10:35\n");
    if (x = dtcvasc("2007-02-11 3:10:35", &dt1))
      printf("Result =  failed with conversion error: %d\n", x);
    else
      printf("Result = successful conversion\n");

    /*
     * Note that the following literal string has a 26 in the hours place
     */
    printf("\nDatetime string #2 = 2007-02-04 26:10:35\n");
    if (x = dtcvasc("2007-02-04 26:10:35", &dt1))
      printf("Result =  failed with conversion error: %d\n", x);
    else
      printf("Result = successful conversion\n");

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

Output

DTCVASC Sample ESQL Program running.

Datetime string #1 = 2007-02-11 3:10:35
Result =  successful conversion

Datetime string #2 = 2007-02-04 26:10:35
Result = failed with conversion error:-1263 

DTCVASC Sample Program over.