5

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)

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Lee
  • 101
  • 1
  • 2
  • 6

3 Answers3

6
DECLARE castTime TIME;
SET castTime = CAST (timeValue AS TIME FORMAT timePattern)

where pattern can be

enter image description here

Richie
  • 9,006
  • 5
  • 25
  • 38
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.

  • 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