CURRENT_TIME format in esql

What is the default format of the CURRENT_TIME function in esql and how we can change it according to our requirements (formats 24 hours or 12 hours).

+4
source share
3 answers
DECLARE castTime TIME; SET castTime = CAST (timeValue AS TIME FORMAT timePattern) 

where the pattern may be

enter image description here

+5
source

Just a little more to clarify things: the CURRENT_TIME function returns a TIME value that has no format. The format is applicable only when passing it to 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'); 

See the other answers to find the format string you need.

+1
source

It is possible that there is no information on how you can configure whether you want to have the format 24h or 12h. You can get this information from the same source @DaveZiegler noted:

  • h | hour at am or pm (1-12)
  • hh | hour at am or pm (01-12)
  • H | hour in 24 hour form (0-23)
  • Hh | hour in 24 hours (00-23)

There is a footnote for the 24th format:

24-hour fields can lead to an undefined time if a conflict field am / pm is specified.

So use h , hh , h or hh with the templates listed in the documentation .

0
source

All Articles