Skip to Content

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.

/wp-content/uploads/2012/04/currentdate_91392.jpg

Step2: Mapping logic as converted from input  like “mm/dd/yyyy HH:mm:ss” to  “mm/dd/yyyy hh:mm:ss AM/PM”

/wp-content/uploads/2012/04/timef_91393.jpg

finally the result is :

/wp-content/uploads/2012/04/currop_91394.jpg

example2: Repeat the above logic with  “Input parameter” and here we have taken “SYSTEM”  as Input parameter.

/wp-content/uploads/2012/04/system_91395.jpg

result is:

/wp-content/uploads/2012/04/pm_91396.jpg

/wp-content/uploads/2012/04/am_91397.jpg

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.

for ex:

/wp-content/uploads/2012/04/datet_91616.jpg

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 :

/wp-content/uploads/2012/04/op_91617.jpg

Thanks,

To report this post you need to login first.

6 Comments

You must be Logged on to comment or reply to a post.

  1. Jacob Vandborg

    Hi Solasu.

    Why don’t you just use the DateTrans function to do the conversion for you?

    There’s no need to create a field-mapping of 13 functions, when it can be done using only DateTrans. According to SAP documentation the functions under Date-category adheres to java.util.SimpleDateFormat, which allows you to specify exactly the date format you might need.

    Best regards,

    Jacob

    (0) 
    1. S Bhavani Sankar Post author

      i agree that is possiable in some cases and this is converting 24 h to 12 h format .

      if u use dateTrans function , 03/03/2011 22:11:11 it’s input converting to

      03/03/2011 22/11/11 PM

      but my logic is converted to

      03/03/2011 10/11/11 PM
      (0) 
      1. Jacob Vandborg

        Hi Bhavani,

        You should keep in mind that HH is Hour in day (0-23) and hh is Hour in am/pm (1-12). It seems like the output date format you used in DateTrans included HH instead of hh.

        Best regards,

        Jacob

        (0) 

Leave a Reply