%DATETIME

Return the date and time

WSupported on Windows
USupported on Unix
VSupported on OpenVMS
NSupported in Synergy .NET
date = %DATETIME[(utc_offset)]

Return value

date

The current date and time. (a20)

Arguments

utc_offset

(optional) The optional offset in minutes east of the Greenwich Meridian. (n)

Discussion

The date and time are returned in the format YYYYMMDDhhmmssuuuuuu:

YYYY

The four-digit year (for example, 2016)

MM

The month (01 through 12)

DD

The day of the month (01 through 31)

hh

The hour (00 through 23)

mm

The minute of the hour (00 through 59)

ss

The second of the minute (00 through 59)

uuuuuu

The microseconds (000000 through 999999)

If your operating system doesn’t provide all six microsecond digits, any unknown digits are returned as zeros.

If utc_offset is specified, %DATETIME returns the Coordinated Universal Time (UTC) date and time. If utc_offset is 0 or not specified, the date and time are the local date and time.

See also

%TIMEZONE routine

Examples

subroutine sh_date_time
record
    group datetime      ,a20
     group date         ,a8 
       year               ,a4
       month              ,a2
       day               ,a2
     endgroup
     group time         ,a12
       hour               ,a2
       minute             ,a2
       second             ,a2
       msecond            ,a6
     endgroup
    endgroup
    string              ,a60
    slen                ,d3
proc
    datetime = %datetime
    xcall s_bld(string, slen, 
  &       "Date and Time: %A = %A/%A/%A %A:%A:%A", datetime, day, month, 
  &       year, hour, minute, second)
    writes(TTCHN, string)
    return
endsubroutine

In the example below, passing %TIMEZONE as the optional argument to %DATETIME causes %DATETIME to return the UTC date and time string.

utc_date = %datetime(%timezone)