What is the default format of the function CURRENT_TIME in esql and how do we change it as per our requirements(24 hr or 12 hr formats)
Asked
Active
Viewed 1.3k times
3 Answers
6
DECLARE castTime TIME;
SET castTime = CAST (timeValue AS TIME FORMAT timePattern)
where pattern can be

Richie
- 9,006
- 5
- 25
- 38
-
Please maek this as answer if this helped – Richie Apr 11 '13 at 05:19
-
3Source: http://www-01.ibm.com/support/knowledgecenter/SSMKHH_9.0.0/com.ibm.etools.mft.doc/ak05616_.htm?lang=en – Dave Ziegler Aug 11 '14 at 15:49
1
Just to clarify things a little more: The CURRENT_TIME function returns a value of the type TIME, which has no format. The format is only relevant when casting it to a CHARACTER:
DECLARE now12, now24 CHARACTER;
SET now12 = CAST (CURRENT_TIME AS CHARACTER FORMAT 'h:mma');
SET now24 = CAST (CURRENT_TIME AS CHARACTER FORMAT 'hh:mm');
To find the right format-string have a look at the other answers.

Thomas Pohl
- 69
- 3
-
Ahh no 'h' means 12 hour suppress leading zeroes and 'hh' is 12 hour include leading zeroes. Its lower case 'h' 12 hour vs upper case 'H' 24 hour clocks. – TJA May 31 '18 at 12:42
0
Maybe whats missing is the information, how you can configure if you want to have 24h or 12h format. You can get this information from the same source @DaveZiegler mentioned:
- h | hour in am or pm (1-12)
- hh | hour in am or pm (01-12)
- H | hour of day in 24 hour form (0-23)
- HH | hour of day in 24 hour form (00-23)
There's a footnote for 24h format:
24-hour fields might result in an ambiguous time, if specified with a conflicting am/pm field.
So use h
, hh
, H
or HH
with the patterns listed in the documentation.

Yannick
- 663
- 1
- 10
- 33