Discussion
Aaseya IT Services
SA
Last activity: 9 Aug 2021 6:26 EDT
Adding Text value to Date format eg :"Aug-01st-2021"
Hi Everyone,
Here I am sharing, how to set Date format as "Aug-01st-2021" (MMM-dd-YYYY). Of course we have Default dates formats for DateTime Control like DD-MM-YYYY (or) MM-dd-YYYY etc, But we don't have direct format or function to get the Date in above format (Need to append st/nd/rd/th for Date value). I have achieved this requirement with a simple Data Transform. Here are the steps below.
Note: All Params are Text type.
Step 1:Param.TodayDate to pyWorkPage.pxCreateDateTime
Step 2: Set Param.Date to @(Pega-RULES:DateTime).FormatDateTime(.pxCreateDateTime, "MMM-dd-YYYY h:mm a",null,"EST").
Step 3: Set Param.Date1 to@substring(Param.Date,0,11)
Step 4: Set Param.Date2 to @substring(Param.Date1,4,6)
Step 5: Set Param.Date3 to @substring(Param.Date1,0,4)
Step 6: Set Param.Date4 to @substring(Param.Date1,6,11).
Now divide Dates into 4 groups based on append values "st, nd, rd and th" to Dates
Group 1st :: 01, 21, 31 Group 2nd:: 02, 22 Group 3rd: 03, 23 and
Group 4th:: Include all other dates excepted from Group1, 2& 3. i.e 04, 05, 06.....30.
Step 7: Create a When rule Param.Date2=01||Param.Date2=21||Param.Date2=31 and Set Param.DateOut to Param.Date2 + "st"
Step 8: Create a When rule Param.Date2=02||Param.Date2=22 and Set Param.DateOut to Param.Date2 + "nd"
Step 9: Create a When rule Param.Date2=03||Param.Date2=23 and Set Param.DateOut to Param.Date2 + "rd"
Step 10: Create a When rule Param.Date2=04||Param.Date2=05||Param.Date2=06||Param.Date2=07||Param.Date2=08||Param.Date2=09||Param.Date2=10||Param.Date2=11||Param.Date2=12||Param.Date2=13||Param.Date2=14||Param.Date2=15||Param.Date2=16||Param.Date2=17||Param.Date2=18||Param.Date2=19||Param.Date2=20||Param.Date2=24||Param.Date2=25||Param.Date2=26||Param.Date2=27||Param.Date2=28||Param.Date2=29||Param.Date2=30 and
Set Param.DateOut to Param.Date2+ "th"
Step 11: Set .TripDate to Param.Date3 + Param.DateOut+ Param.Date4
Now run the DT and check Output. This codes works for all months in a year.
For more clear understanding, please go through with below attached document.
Thanks and Regards
Srujan Bollipally