Skip to content
Advertisement

SQL (HUE) : Is there any way to convert 24 hrs time into 12 hrs AM / PM format with hours buckets

I have table A which contains column time stored as timestamp datatype.

Table A: Contains time column in HH:MM:SS in 24 hrs format.

Advertisement

Answer

Please use below code. Replace now() with time for your query.

Explanation – firstly i am checking if hour is >12. If yes, deducting 12 to get the hour.
Then setting up AM/PM based on hour.
lpad is used to make sure you get data in 01 AM format. enter image description here

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement