I have a soql query in which I'm retrieving the hour of the day which is in 24 hour format I want that to converted into 12 hour format while retrieving from soql query.

Is there any way to achieve this?

The date function I'm using is HOUR_IN_DAY(CreatedDate)

Thanks, Prasanth

  • Do you want in apex?
    – Ratan Paul
    Dec 23, 2015 at 10:01
  • Hi Ratan, That will be great if I get this in apex.But do we have any specific function to do this? Thanks Dec 23, 2015 at 10:04

1 Answer 1


Try with this code in your developer console.

for(Account obj : [SELECT Id, CreatedDate FROM Account LIMIT 20]){
    Datetime myDateTime = obj.CreatedDate;
    String dtConverted = myDateTime.format('MM/dd/yyyy h a');


enter image description here

  • you are simply awesome. Thank you very much Ratan. Dec 23, 2015 at 10:13
  • 1
    Most welcome @prasanthcheenu
    – Ratan Paul
    Dec 23, 2015 at 10:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .