The dtaddinv() function

The dtaddinv() function adds an interval value to a datetime value. The result is a datetime value.

Syntax

mint dtaddinv(dt, inv, res)
   dtime_t *dt;
   intrvl_t *inv;
   dtime_t *res;
dt
A pointer to the initialized datetime host variable.
inv
A pointer to the initialized interval host variable.
res
A pointer to the datetime host variable that contains the result.

Usage

The dtaddinv() function adds the interval value in inv to the datetime value in dt and stores the datetime value in res. This result inherits the qualifier of dt.

The interval value must be in either the year to month or day to fraction(5) ranges.

The datetime value must include all the fields present in the interval value.

If you do not initialize the variables dt and inv, the function might return an unpredictable result.

Return codes

0
The addition was successful.
<0
Error in addition.

Example

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

   The following program adds an INTERVAL value to a DATETIME value and 
   displays the result.
*/

#include <stdio.h>

EXEC SQL include datetime;

main()
{
    char out_str[16];

    EXEC SQL BEGIN DECLARE SECTION;    
      datetime year to minute dt_var, result;
      interval day to minute intvl;
    EXEC SQL END DECLARE SECTION;

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

    printf("datetime year to minute value=2006-11-28 11:40\n");
    dtcvasc("2006-11-28 11:40", &dt_var);
    printf("interval day to minute value = 50 10:20\n");
    incvasc("50 10:20", &intvl);

    dtaddinv(&dt_var, &intvl, &result);

    /* Convert to ASCII for displaying */
    dttoasc(&result, out_str);
    printf("-----------------------------------------------------------\n");
    printf("                                         Sum=%s\n", out_str);

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

Output

DTADDINV Sample ESQL Program running.

datetime year to minute value=2006-11-28 11:40
interval day to minute value =        50 10:20
-----------------------------------------------
                          Sum=2007-01-17 22:00

DTADDINV Sample Program over.