SQL/MP Reference Manual

HP NonStop SQL/MP Reference Manual523352-013
C-174
CURRENT_TIMESTAMP Function
CURRENT_TIMESTAMP Function
CURRENT_TIMESTAMP is an SQLCI function that returns a Julian timestamp in
Greenwich mean time for the current date and time. The data type of the returned
value is NUMERIC(18) or LARGEINT.
CURRENT_TIMESTAMP works in the SQLCI commands BREAK FOOTING, BREAK
TITLE, DETAIL, EXECUTE, PAGE FOOTING, PAGE TITLE, REPORT FOOTING,
REPORT TITLE, and SET PARAM. It does not work in DML statements or other SQL
statements.
Considerations—CURRENT_TIMESTAMP
In reports, CURRENT_TIMESTAMP returns a new value for each detail line
printed. If you want the value of a timestamp to remain constant throughout a
report, use CURRENT instead of CURRENT_TIMESTAMP. SQLCI determines the
value of CURRENT only once for each query. (For example, if you use CURRENT
in a report title and footing, the printed timestamp value is the same in both
places.) CURRENT returns a timestamp with data type DATETIME.
If you specify CURRENT_TIMESTAMP as a parameter value in a SET PARAM or
EXECUTE, it returns a timestamp for the time SET PARAM or EXECUTE
executes. Note that the results depend on whether you set the parameter in SET
PARAM or EXECUTE.
For example, these statements execute statement S (which uses parameter ?T)
twice, using a different Julian timestamp for each execution:
EXECUTE S USING ?T=CURRENT_TIMESTAMP; EXECUTE S
USING ?T=CURRENT_TIMESTAMP;
In contrast, this statement also execute the same statement S twice, but use the
same Julian timestamp (the time SET PARAM executed) for each execution:
SET PARAM ?T CURRENT_TIMESTAMP; EXECUTE S; EXECUTE S:
Example—CURRENT_TIMESTAMP
To print the current date in a detail line, include these items in the print list:
"Date: ", CURRENT_TIMESTAMP AS DATE "D2/M2/Y2", SPACE 5,
"Time: ", CURRENT_TIMESTAMP AS TIME "HP2:M2"
For example, on March 15, 2004 at 1:30 p.m., the detail line prints:
Date: 03/15/04 Time: 01:30 PM
CURRENT_TIMESTAMP