The dtcurrent() function

The dtcurrent() function assigns the current date and time to a datetime variable.

Syntax

void dtcurrent(d)
   dtime_t *d;
d
A pointer to the initialized datetime host variable.

Usage

When the variable qualifier is set to zero (or any invalid qualifier), the dtcurrent() function initializes it with the year to fraction(3) qualifier.

When the variable contains a valid qualifier, the dtcurrent() function extends the current date and time to agree with the qualifier.

Example calls

The following statements set the host variable timewarp to the current date:
EXEC SQL BEGIN DECLARE SECTION;
    datetime year to day timewarp;
EXEC SQL END DECLARE SECTION;

dtcurrent(&timewarp);
The following statements set the variable now to the current time, to the nearest millisecond:
now.dt_qual = TU_DTENCODE(TU_HOUR,TU_F3);
dtcurrent(&now);

Example

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

   The following program obtains the current date from the system, converts 
   it to ASCII and prints it.
*/

#include <stdio.h>

EXEC SQL include datetime;

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

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

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

    /* Get today's date */
    dtcurrent(&dt1);

    /* Convert to ASCII for displaying */
    dttoasc(&dt1, out_str);
    printf("\tToday's datetime (year to minute) value is %s\n", out_str);

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

Output

DTCURRENT Sample ESQL Program running.

   Today's datetime (year to minute) value is 2007-09-16 14:49

DTCURRENT Sample Program over.