Bug using TO_CHAR to Convert Time to 12 Hour Format?

Moderator: NorbertKrupa

Post Reply
User avatar
becky
Intermediate
Intermediate
Posts: 118
Joined: Sat Apr 28, 2012 11:37 am

Bug using TO_CHAR to Convert Time to 12 Hour Format?

Post by becky » Tue Aug 21, 2012 6:32 pm

Hi all,

Am I doing something wrong with converting a date to string when I want the hours to in 12 hour and not 24 hour format?

Code: Select all

dbadmin=> select sysdate, to_char(sysdate, 'HH:MI AM');
          sysdate           | to_char
----------------------------+----------
 2012-08-21 13:31:07.529333 | 13:31 PM
(1 row)
Notice the TO_CHAR shows 13:31 instead of 1:31 PM...

Update: Note that the HH format worked fine in Vertica 5 to convert to 12 hour clock when used in conjunction with AM or PM... I am having this issue in Vertica 6.
THANKS - BECKSTER

User avatar
JimKnicely
Site Admin
Site Admin
Posts: 1825
Joined: Sat Jan 21, 2012 4:58 am
Contact:

Re: Bug using TO_CHAR to Convert Time to 12 Hour Format?

Post by JimKnicely » Wed Aug 22, 2012 1:24 am

Becky,

In Vertica 5 although the docs said HH has the range of 00-23, it actually did 01-12 when ever we added an AM or PM to the template in the TO_CHAR function. In Vertica 6 it must have been fixed so that we have to explicitly put HH12 when we want the 12 hour format. Although, I would concur that it doesn't make sense that HH:MI PM would produce military time. It's never 13:00 PM ...
Jim Knicely

Image

Note: I work for Vertica. My views, opinions, and thoughts expressed here do not represent those of my employer.

Post Reply

Return to “Vertica SQL”