Saturday, September 29, 2018

How to convert java date to Pega Date and DateTime

In Pega, date would be stored as YYYYMMDD.
In Java, we have many acceptable formats. Let's say 2018-09-29 YYYY-MM-DD

If we have to convert Java date to Pega Date, you can use ConvertDate function.

Java Date to Pega Date:
@ConvertDate(Param.JavaFormatDate)
where Param.JavaFormatDate=2018-09-29

Pega Date to Pega Date time:
There are many ways to achieve it. Easiest way is by using function @addToDate(Param.PegaDate,0,0,0,0,0)
by keeping no of days, hours, mins, sec, ms to 0.
For example, if Param.PegaDate=20180929 then output after conversion to datetime is : 20180929T000000.000 GMT
Note: This would give a datetime in format of GMT

This is the basic understanding. If we are clear with this, we can easily achieve requirements.

Scenario with timezone:
When Pega datetime of format GMT is saved to DB, let's say if the server is in HKT
In the above example, on clipboard
Pega datetime=20180929T000000.000 GMT
In DB datetime =2018-09-29 08:00:00.000
Note: HKT=GMT+8hours

No comments:

Post a Comment


HowToPega : All rights reserved and the contents are copyrighted to Pavan Kumar Naidu