The incvfmtasc() function

The incvfmtasc() function uses a formatting mask to convert a character string to an interval value.

Syntax

mint incvfmtasc(inbuf, fmtstring, invvalue)
   char *inbuf;
   char *fmtstring;
   intrvl_t *invvalue;
inbuf
A pointer to a buffer that contains the string to convert.
fmtstring
A pointer to the buffer that contains the formatting mask to use for the inbuf string. This time-formatting mask contains the same formatting directives that the DBTIME environment variable supports. (For a list of these directives, see the description of DBTIME in the Informix® Guide to SQL: Reference).
invvalue
A pointer to the initialized interval variable.

Usage

You must initialize the interval variable in invvalue with the qualifier you want this variable to have. The interval variable does not need to specify the same qualifier as the formatting mask. When the interval qualifier is different from the implied formatting-mask qualifier, incvfmtasc() converts the result to appropriate units as necessary. However, both qualifiers must belong to the same interval class: either the year to month class or the day to fraction class.

All fields in the character string in inbuf must be contiguous. In other words, if the qualifier is hour to second, you must specify all values for hour, minute, and second somewhere in the string, or incvfmtasc() returns an error.

The inbuf character string can have leading and trailing spaces. However, from the first significant digit to the last, inbuf can contain only digits and delimiters that are appropriate for the qualifier fields that the formatting mask implies.

If the character string is acceptable, the incvfmtasc() function sets the interval value in invvalue and returns zero. Otherwise, the function returns an error code and the interval variable contains an unpredictable value.

The formatting directives %B, %b, and %p, which the DBTIME environment variable accepts, are not applicable in fmtstring because month name and a.m./p.m. information is not relevant for intervals of time. Use the %Y directive if the interval is more than 99 years (%y can handle only two digits). For hours, use %H (not %I, because %I can represent only 12 hours). If fmtstring is an empty string, the function returns an error.

Return codes

0
The conversion was successful.
<0
The conversion failed.

Example

The demo directory contains this sample program in the file incvfmtasc.ec.
/* *incvfmtasc.ec*
 The following program illustrates the conversion of two strings
 to three interval values.
*/

#include <stdio.h>

EXEC SQL include datetime;

main()
{
     char out_str[30];
     char out_str2[30];
     char out_str3[30];
     mint x;


EXEC SQL BEGIN DECLARE SECTION;
      interval day to minute short_time;
      interval minute(5) to second moment;
      interval hour to second long_moment;
     EXEC SQL END DECLARE SECTION;

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

   /* Initialize short_time */
   printf("Interval value #1 = 20 days, 3 hours, 40 minutes\n");
      x = incvfmtasc("20 days, 3 hours, 40 minutes",
       "%d days, %H hours, %M minutes", &short_time);

   /*Convert the internal format to ascii in ANSI format, for displaying. */
    x = intoasc(&short_time, out_str);
    printf("Interval value (day to minute) = %s\n", out_str);

   /* Initialize moment */
   printf("\nInterval value #2 = 428 minutes, 30 seconds\n");
   x = incvfmtasc("428 minutes, 30 seconds",
       "%M minutes, %S seconds", &moment);

   /* Convert the internal format to ascii in ANSI format, for displaying. */
    x = intoasc(&moment, out_str2);
    printf("Interval value (minute to second) = %s\n", out_str2);

   /* Initialize long_moment */
   printf("\nInterval value #3 = 428 minutes, 30 seconds\n");
    x = incvfmtasc("428 minutes, 30 seconds",
       "%M minutes, %S seconds", &long_moment);

   /*Convert the internal format to ascii in ANSI format, for displaying. */
    x = intoasc(&long_moment, out_str3);
    printf("Interval value (hour to second) = %s\n", out_str3);

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

Output

INVCFMTASC Sample ESQL Program running.

Interval value #1 = 20 days, 3 hours, 40 minutes
Interval value (day to minute) = 20 03:40

Interval value #2 = 428 minutes, 30 seconds
Interval value (minute to second) = 428:30

Interval value #3 = 428 minute, 30 seconds
Interval value (hour to second) = 7:08:30

INVCFMTASC Sample Program over.