The dtsubinv() function

The dtsubinv() function subtracts an interval value from a datetime value. The result is a datetime value.

Syntax

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

Usage

The dtsubinv() function subtracts the interval value in inv from the datetime value in dt and stores the datetime value in res. This result inherits the qualifier of dt.

The datetime value must include all the fields present in the interval value. When you do not initialize the variables dt and inv, the function might return an unpredictable result.

Return codes

0
The subtraction was successful.
<0
An error occurred while performing the subtraction.

Example

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

   The following program subtracts an INTERVAL value from 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("DTSUBINV Sample ESQL Program running.\n\n");

    printf("Datetime (year to month) value = 2007-11-28\n");
    dtcvasc("2007-11-28 11:40", &dt_var);
    printf("Interval (day to minute) value   =     50 10:20\n");
    incvasc("50 10:20", &intvl);

    printf("-----------------------------------------------\n");
    dtsubinv(&dt_var, &intvl, &result);

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

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

Output

DTSUBINV Sample ESQL Program running.

Datetime (year to month) value = 2007-11-28
Interval (day to minute) value =   50 10:20
-----------------------------------------------------
Difference (year to hour)      = 2007-10-09  01:20

DTSUBINV Sample Program over.