Click here to Skip to main content
15,885,629 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everyone,
I am trying to get hh: mm AM in 24-hour format from timestamp column.
any help will be highly appreciated! Thanks!!

What I have tried:

Here is the query I have written:
select to_varchar(Date_column, 'HH:mm AM') 

The example output is 23:06 PM...

How can I convert it to 11:06 PM?
I am writing the query in Snowflake web UI. 
Posted
Updated 16-Jun-20 22:39pm
Comments
MadMyche 11-Jun-20 8:09am    
What type of DB and client are you using?

Take a look at the documentation: TO_CHAR , TO_VARCHAR — Snowflake Documentation[^]
There's a link to Conversion Functions — Snowflake Documentation[^], which says:

Quote:
AM , PM - Ante meridiem (am) / post meridiem (pm); for use with HH12.


BTW: MM is used to get 2 digits month. To get minutes, use MI instead.

So, finally it should be:
SQL
select to_varchar(Date_column, 'HH12:MI AM')


Note: i can't test it!
 
Share this answer
 
Try this
SQL
select convert(varchar, Date_column, 114)
 
Share this answer
 
Comments
MadMyche 11-Jun-20 8:11am    
Did you read the format that is desired? Formats 14/114 output in 24H format with seconds

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900