SQL/MX Report Writer Guide
Customizing a Report
HP NonStop SQL/MX Report Writer Guide—527194-002
4-42
Formatting Dates and Times
Formatting Dates and Times
To format a date and time in your report, you must consider the data type of the date
and time value to be formatted. The data type is determined by the way the value is
generated or stored.
Date and Time Values
A report can contain dates and times selected from columns of the DATETIME, DATE,
TIME, or TIMESTAMP data types. You can also use date-time literals or expressions to
generate dates and times for a report. For a complete description of date-time data
types and literals, see the SQL/MX Reference Manual.
You can compute a date and time by using the COMPUTE_TIMESTAMP,
CURRENT_TIMESTAMP, or CURRENT function:
•
The COMPUTE_TIMESTAMP function produces a Julian timestamp (sometimes
called a Guardian timestamp) for the date and, optionally, the time you specify:
COMPUTE_TIMESTAMP (6/18/2000 05:20:30:000:000)
or
COMPUTE_TIMESTAMP (6/18/2000)
The data type of a Julian timestamp is LARGEINT.
•
The CURRENT_TIMESTAMP function produces a Julian timestamp for the current
date and time at the time the line containing CURRENT_TIMESTAMP is printed.
Therefore, if you use CURRENT_TIMESTAMP in the report title and the report
footing, the times printed might differ. The data type of the result is LARGEINT.
COMPUTE_TIMESTAMP and CURRENT_TIMESTAMP are report writer functions
and can be used only in report command print lists and in the SET PARAM and
EXECUTE commands. For an example of using the SET PARAM command, see
Using Parameters With SELECT Commands on page 3-24.
•
The CURRENT function produces a timestamp for the current date and time. The
result is a value of data type TIMESTAMP. Each time you execute a SELECT
command, a TIMESTAMP value is generated and saved until you execute another
SELECT command. Regardless of where you specify CURRENT, the date and
time returned is based on the TIMESTAMP value generated when the previous
SELECT command was executed.
You can use the CURRENT function (and all other SQL/MX date-time functions)
anywhere that an SQL expression is allowed. Functions can be used with the
SELECT command, the value list of an INSERT or UPDATE command, and a
report command print list. You cannot use the CURRENT function in a SET
PARAM or EXECUTE command. For descriptions of SQL date-time functions, see
the SQL/MX Reference Manual.