formatTimestamp()
The strLib.formatTimestamp() system function accepts a TIMESTAMP value as input and returns a STRING value.
EGL tries the following formats for the conversion, in order. If
a particular format is null, empty, or not valid, EGL moves to the
next:
- The format string provided as a parameter
- strLib.defaultTimestampFormat
- The mask with which the TIMESTAMP variable was defined
When converting a TIMESTAMP based on its defining mask, EGL inserts
the following characters:
- Dashes as separators between date components
- A space between dates and times
- Colons between time components
- A decimal point (a period, not a locale dependent character) between seconds and fractions of seconds
For more information, see the second example in this topic.
Syntax
strLib.formatTimestamp(
aTimeStamp TIMESTAMP(yyyyMMddHHmmssSSSSSS)? in
[, timestampFormat STRING? in
])
returns (result STRING?)
- aTimeStamp
- The TIMESTAMP value to be formatted. The input can be any expression that is assignment compatible with a TIMESTAMP value, such as the value returned by the dateTimeLib.currentTimestamp() system function.
- timestampFormat
- Identifies the timestamp format, as described in Date/time masks and format specifiers. You can use a literal, a string variable, or any of the timestamp format constants described in EGL library strLib.
- result
- A STRING variable. If aTimeStamp is not valid, the function returns a null value.
Examples
This example provides a complex format pattern:
myTs TIMESTAMP = "20060606123200";
myFormat STRING = "MMMMMMMMM dd, yyyy ' at ' hh:mm aa";
result STRING;
result = strLib.formatTimestamp(myTs,myFormat);
// result is "June 6, 2006 at 12:32 pm"
In the next example, EGL uses masks from the variables to create the strings:
ts1 timestamp( "yyyyMMddHHmmssffffff" );
ts2 timestamp( "yyyyMMdd" );
ts3 timestamp( "MMddHHmmssff" );
tsString STRING;
defaultTimestampFormat = "";
// uses pattern yyyy-MM-dd HH:mm:ss.SSSSSS
tsString = formatTimestamp( ts1 );
// uses pattern yyyy-MM-dd
tsString = formatTimestamp( ts2 );
// uses pattern MM-dd HH:mm:ss.SS
tsString = formatTimestamp( ts3 );