The dtextend() function

The dtextend() function extends a datetime value to a different qualifier. Extending is the operation of adding or dropping fields of a DATETIME value to make it match a given qualifier.

Syntax

mint dtextend(in_dt, out_dt)
   dtime_t *in_dt, *out_dt;
in_dt
A pointer to the datetime variable to extend.
out_dt
A pointer to the datetime variable with a valid qualifier to use for the extension.

Usage

The dtextend() function copies the qualifier-field digits of the in_dt datetime variable to the out_dt datetime variable. The qualifier of the out_dt variable controls the copy.

The function discards any fields in in_dt that the out_dt variable does not include. The function complets any fields in out_dt that are not present in in_dt, as follows:
  • It completes fields to the left of the most-significant field in in_dt from the current time and date.
  • It completes fields to the right of the least-significant field in in_dt with zeros.
In the following example, a variable fiscal_start is set up with the first day of a fiscal year that begins on June 1. The dtextend() function generates the current year.
EXEC SQL BEGIN DECLARE SECTION;
    datetime work, fiscal_start;
EXEC SQL END DECLARE SECTION;

work.dt_qual = TU_DTENCODE(TU_MONTH,TU_DAY);
dtcvasc("06-01",&work);
fiscal_start.dt_qual = TU_DTENCODE(TU_YEAR,TU_DAY);
dtextend(&work,&fiscal_start);

Return codes

0
The operation was successful.
-1268
A parameter contains an invalid datetime qualifier.

Example

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

   The following program illustrates the results of datetime extension.
   The fields to the right are filled with zeros,
   and the fields to the left are filled in from current date and time.
*/

#include <stdio.h>

EXEC SQL include datetime;

main()
{
    mint x;
    char year_str[20];

    EXEC SQL BEGIN DECLARE SECTION;
      datetime month to day month_dt;
      datetime year to minute year_min;
    EXEC SQL END DECLARE SECTION;

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

    /* Assign value to month_dt and extend */
    printf("Datetime (month to day) value = 12-07\n");
    if(x = dtcvasc("12-07", &month_dt))
       printf("Result = Error %d in dtcvasc()\n", x);
else
      {
       if (x = dtextend(&month_dt, &year_min))
         printf("Result = Error %d in dtextend()\n", x);
      else
         {
          dttoasc(&year_min, year_str);
         printf("Datetime (year to minute) extended value =%s\n", 
            year_str);
         }
      }

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

Output

DTEXTEND Sample ESQL Program running.

Datetime (month to day) value = 12-07
Datetime (year to minute) extended value = 2006-12-07 00:00

DTEXTEND Sample Program over.