Date time functions in Pega

This Post is about the date time functions in pega and how to use them.
Everytime I need to use Pega function which I have rarely used , I try to find, how to pass the parameters from references and try the same , this post is going to help me to check all the syntax of frequently used functions in single page.


Click the button to copy the syntax now

Function Get current date time
Syntax
Notes Returns the Current Date time in GMT Format
For example: @CurrentDateTime()
Function Format date Time (accept only Datetime)
Syntax
Notes Returns the formatted Date time in GMT Format For example:@DateTime.FormatDateTime("20200611T020304.000 GMT","dd/MM/yyyy","","")
@DateTime.FormatDateTime("20200611T020304.000 GMT","yyyy-MM-dd HH:mm:ss a","Europe/London","en_GB")
Function Add to Date (accept only Date/Datetime)
Syntax
Notes Returns the Modified Date time in GMT Format after adding days,hr,mins,seconds For example: @DateTime.addToDate("20200611T020304.000 GMT",1,2,3,4)
@DateTime.addToDate("20200610",1,2,3,4)
Function Date Time Difference (accept only Datetime)
Syntax
Notes Returns the Date time difference in decimal Format
Precision: C-century, Y-Year, M-Month, D-Days, h-hour, m-minutes, s-seconds, S-microseconds
For example:
@DateTime.DateTimeDifference("20200611T020304.000 GMT","20210611T020304.000 GMT",Y)
Function compare two Dates By Days
Syntax
Notes Returns true if Big date is greater than small date by no of days
For example:
@DateTime.compareDatesByDays("20200614T020304.000 GMT","20200609T020304.000 GMT",4)
Function Get base date from integer
Syntax
Notes Returns a BigDecimal value of difference between the year, month, day and Jan 1 ,1970
For example: @date(2009,2,1)
Function Get base date from string
Syntax
Notes Returns a BigDecimal value of difference between the specificed string
For example: @dateValue("20200621T114952.842 GMT")
@dateValue("20200621")

Function Get Date[1 to 31] from BigDecimal
Syntax
Notes Returns the int value corresponding to the day from Bigdecimal/Double
For example: @day(18434)
@day(@dateValue("20200621T114952.842 GMT"))

Function Get month[1 to 11]from BigDecimal
Syntax
Notes Returns the int value corresponding to the month from Bigdecimal/Double
For example: @month(18434)
@month(@dateValue("20200621T114952.842 GMT"))

Function Get Year from BigDecimal
Syntax
Notes Returns the int value corresponding to the year from Bigdecimal/Double
For example: @year(18434)
@year(@dateValue("20200621T114952.842 GMT"))
Function Get today date in BigDecimal
Syntax
Notes Returns the BigDecimal value (Pega Platform Date) corresponding to the current date
For example: @today()


Please comment , if you need any function to be included here

Why Pega OOTB functions

Why to Use Pega OOTB functions ?

Let's take a small scenario to check why should I should go with Pega functions instead of custom approach

Consider you have Pagelist and you need to find the Length of Pagelist

There are two approaches to find the pagelist
1) Loop through the pagelist and find the count
2) Use Pega -in built functions

Method 1: Loop through the pagelist and find the count

Here , we have written sample DT and Loop through the Pagelist and find the count


Tracing this Data transform , it takes 0.0090 seconds to complete the Data transfrom


Method 2: Use Pega -in built functions


Here , Using same sample DT and pega OOTB function to find the count



Tracing this Data transform , it takes 0.0060 seconds to process the Data transform

Should we go with Pega OOTB functions ? just because it takes less time which is less than a second.

Yes, this is one of the reason.
Let's check the processing time in percentage.😱



Considering the huge amount of code which is modified with Pega OOTB functions can significantly improve the performance of your application.

Functions and Syntax in Pega

This Post is about the functions in pega and how to use them.
Everytime I need to use Pega function which I have rarely used , I try to find, how to pass the parameters from references and try the same , this post is going to help me to check all the syntax of frequently used functions in single page.

I have written separate post on , why we need to use Pega built in functions

Click the button to copy the syntax now

Date time Functions are added.Click here

Pagelist Functions are added.Click here

Function Generate ID
Syntax
Notes C- is an example of Prefix, this can be replaced with prefix of required.
@pzGenerateUniqueID(tools, "C-")
Function Get DSSValue in pega
Syntax
Notes For example: @getDataSystemSetting(ApplyJobs,NotificationExpiry)
Function To Log Message
Syntax
Notes Logs the message for specified level in pega logs.
[d- debug],[i-info],[f-infoforced],[w-warning],[e-error]
For example : @Default.pxLogMessage("Hello Testing",'f')
Function Delete all instance of Data Page
Syntax
Notes Deletes all instances of Datapage
For example: @(Pega-RULES:DeclarePages).pzDeleteAllInstancesOfDeclarativePage(tools,D_City)
Function To Run Decision Table
Syntax
Notes To run the decision table
For example: @(Pega-RULES:DecisionTable).ObtainValue(tools,Primary,SelectApplication)
Function To convert to Json
Syntax
Notes To convert the property from Page to Json format
For example: @pxConvertPageToString(tools,RequestPage,"json")
Function To convert JSON to Page format
Syntax
Notes To convert the response json into response page property
For example: @pxConvertStringToPage(tools,ResponsePage,Param.ResponseJSON,"json")
Function To Use Regular Expressions to remove HTML Tags
Syntax
Notes To remove the HTML tags formed by the rich text editor
For example: @String.pxReplaceAllViaRegex(.Description,"<(.|\n)*?>","")
/ You can look into the Formatter.pxFormatCommon function java code to see the usage of pzUnescapeHTMLSpecialChars function


Please comment , if you need any function to be included here