I have seen in many Blogs where people asking about several converting time format from 24 hours to 12hours and in most of the cases people have suggested to go for UDF to get the desired TIME format. I hope this blog will be very useful for beginners. Here in this blog i am explaining how to convert time format in different approaches with out udf .
Let’s say we have incoming dates as 05/04/20112 23:57:47 & 06/04/2012 00:01:15 and we want to get the desired output as 05/04/20112 11:57:47 PM and 06/04/2012 00:01:15 AM
To get the above result we don’t need to write any UDF, it is simply possible by using standard functions.
Input: we have to provide CurrentDate function or input parameter.
Approach 1: by using some standard functions for practice
Example 1 : with currentDate
Open the “currentDate” function of the Date Function Group and double click and then selected format (mm/dd/yyyy hh:mm:ss ) and “Target Format” as shown in below picture.
Step2: Mapping logic as converted from input like “mm/dd/yyyy HH:mm:ss” to “mm/dd/yyyy hh:mm:ss AM/PM”
finally the result is :
example2: Repeat the above logic with “Input parameter” and here we have taken “SYSTEM” as Input parameter.
Approach 2: By using Standard Function “dateTrans”:
we have to select dateTrans Function of the Date Function Group then double click and select input parameter and out parameters based on requirement.
note : if we need hours is 12 hours format then we have to change maually hours HH to hh and add a letter end of the parameter as like showing in picture .
output is :