ALTTIME
The ALTTIME function returns the current time in the specified format or converts a user-specified time from one format to another.
The schema is DSN8.
The ALTTIME function returns
the current time in one of the following formats or converts a user-specified
time from one of the formats to another:
H:MM AM/PM HH:MM AM/PM
HH:MM:SS AM/PM HH:MM:SS
H.MM HH.MM
H.MM.SS HH.MM.SS
where:
H: Suppress leading zero if the hour is less than 10
HH: Retain leading zero if the hour is less than 10
M: Suppress leading zero if the minute is less than 10
MM: Retain leading zero if the minute is less than 10
AM/PM: Return time in 12-hour clock format, else 24-hourThe ALTTIME function demonstrates how you can create an overloaded function—a function name for which there are multiple function instances. Each instance supports a different parameter list enabling you to group related but distinct functions in a single user-defined function. The ALTTIME function has two forms.
- Form 1: ALTTIME(output-format)
- This form of the function converts the current time into the specified
format.
- output-format
- A character string that matches one of the 8 time formats that are shown above. The character string must have a data type of VARCHAR and an actual length that is not greater than 14 bytes.
The result of the function is VARCHAR(11).
- Form 2: ALTTIME(input-time, input-format, output-format)
- This form of the function converts a time (input-date)
in one user-specified format (input-format)
into another format (output-format).
- input-time
- The argument must be a time or a character string representation of a time in the format specified by input-format. A character string argument must have a data type of VARCHAR and an actual length that is not greater than 11 bytes.
- input-format
- A character string that matches one of the 8 time formats that are shown above. The character string must have a data type of VARCHAR and an actual length that is not greater than 14 bytes.
- output-format
- A character string that matches one of the 8 time formats that are shown above. The character string must have a data type of VARCHAR and an actual length that is not greater than 14 bytes.
The result of the function is VARCHAR(11).
The following table shows the external program
and specific names for the two forms of the function, which are based
on the input to the function.
| Conversion type | Input arguments | External name | Specific name |
|---|---|---|---|
| Current time | output-format (VARCHAR) | DSN8DUAT | DSN8.DSN8DUATV |
| User-specified time | input-time (VARCHAR)
input-format (VARCHAR) output-format (VARCHAR) |
DSN8DUCT | DSN8.DSN8DUCTVVV |
| input-time (TIME)
input-format (VARCHAR) output-format (VARCHAR) |
DSN8DUCT | DSN8.DSN8DUCTTVV |
Example 1: Convert the current time into a 12-hour
clock format without seconds, 'H.MM AM/PM'.
VALUES DSN8.ALTTIME( 'H:MM AM/PM' );Example
2: Convert the current time into a 24-hour clock format without
seconds, 'HH.MM'.
VALUES DSN8.ALTTIME( 'HH.MM' );Example
3: Convert the current time into a 24-hour clock format with seconds,
'HH.MM.SS'.
VALUES DSN8.ALTTIME( 'HH.MM.SS' );Example
4: Convert '00:00:00', a time in 24-hour clock format with seconds,
to a time in 12-hour clock format without seconds.
VALUES DSN8.ALTTIME( '00:00:00','HH:MM:SS','HH:MM AM/PM' ); The
function returns '12:00 AM'.Example 5: Convert
'00:00:00', a time in 24-hour clock format with seconds, to a time
in 12-hour clock format without seconds and without any leading zero
on the hour.
VALUES DSN8.ALTTIME( '06.42.37','HH.MM.SS','H:MM AM/PM' ); The
function returns '6:42 AM'.