Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us to spark ideas for how to put the latest capabilities into action. Register here!
cancel
Showing results for 
Search instead for 
Did you mean: 
ysj
Creator
Creator

How to fetch hours in 12 hours format in AM and PM?

hi

How to fetch hours in 12 and 24 formats?

5 Replies
prma7799
Master III
Master III

=TimeStamp(now(), 'MM/DD/YYYY hh:mm:ss')

ramasaisaksoft

Time format for 12 horus is 'h:mm:ss' and you need the 'hh:mm:ss' format, so drop one h from Timestamp# function:

Timestamp(Timestamp#(MyTimeStampFieldin12HrsFormat,'h:mm:ss TT') ,'hh:mm:ss') as MyTimeStampFieldin24HrsFormat

ysj
Creator
Creator
Author

I have modified my question.could you please help me in that if you might know

ysj
Creator
Creator
Author

Thank you Rama Sai,

But I am not getting expected results.

vishsaggi
Champion III
Champion III

You want a different field to get your hours ? You can try like

LOAD

     IF(hour(Timestamp(MyHour)) < 12, 'AM',

     IF(hour(Timestamp(MyHour)) >= 12 AND hour(Timestamp(MyHour)) <= 24, 'PM')) AS [AM PM];

LOAD

timestamp(floor(YourdateField) + Maketime(hour(Yourdatefield)), 'hh') as MyHour,

......

FROM yoursource;