Question
Infosys Limited
IN
Last activity: 3 Jan 2017 8:13 EST
Date to be displayed to 1st of next month
Hi i need immediate help where the requirement is to get current date and display the next month's 1st in the property. It should show only 1st of every month.
Example: today its 08/11/2016 when i open that screen the property should show 09/01/2016 and when i open that screen on 09/02/2016 the property should display 10/01/2016.
When we open that screen on 12/04/2016 the property should display 01/01/2017
Please help me on this as soon as possible
***Updated by Moderator: Marissa. Removed user added #helpme tag. Apologies for confusion, shouldn't have been an end-user option***
-
Likes (1)
Ritvik Mohapatra -
Share this page Facebook Twitter LinkedIn Email Copying... Copied!
Accepted Solution
Swedbank AB
SE
Hi Venugopal,
There's no need to add +1 to year, as the function will add 1 month to the current month and will update the year as well(only if it is december).
See the screenshot below for the test run:
- Test Activity
- Output for above activity
Let us know if this suffices your requirement.
Pegasystems Inc.
US
Please provide logic you are using to calculate 1st of month as well as format string used for display.
Infosys Limited
IN
Hi Paul,
Iam using this set property...
LOCAL.day = '01'
LOCAL.month = @(Pega-RULES:DateTime).month(@today())+2
LOCAL.year = @(Pega-RULES:DateTime).year(@today())
PARAM.today = @(Pega-RULES:DateTime).date(LOCAL.year, LOCAL.month, LOCAL.day)
This is working fine, but the problem during Dec 2016 property should show 01/01/2017.. how could this be possible should i use WHEN condition and set the values based in month DEC?
Is there any way fix this using any OOB rule?
thanks & Regards,
venugopal maddukuri.
Pegasystems Inc.
US
I didn't quite find anything more straight forward out there, but you can get creative and utilize some OOTB functions to calculate and manipulate what you're after.
I broke it up into a couple steps so you could see my algorithm more easily. You can use this as proof of concept and starting point. Ultimately you may want to streamline this into an activity or your own data transform, etc.
First I grab the current date.
CurrentDate = @DateTime.getCurrentDateStamp()
Then I reset the date to the first of the month with a little trick using the addCalendar function to actually subtract a calculated date from the current date.
ResetToFirstOfMonth = @DateTime.addCalendar(.CurrentDate,0,0,0,-(@DateTime.day(.CurrentDate) - 1),0,0,0)
Now I'll use the function again as intended and add 1 month to this. (Also note, I am passing the first manipulated date and not the current date this time. If you try to do it all in one shot, you'll need to consider a different algorithm)
AddOneMonth = @DateTime.addCalendar(.ResetToFirstOfMonth,0,1,0,0,0,0,0)
Here is the net effect.
I didn't quite find anything more straight forward out there, but you can get creative and utilize some OOTB functions to calculate and manipulate what you're after.
I broke it up into a couple steps so you could see my algorithm more easily. You can use this as proof of concept and starting point. Ultimately you may want to streamline this into an activity or your own data transform, etc.
First I grab the current date.
CurrentDate = @DateTime.getCurrentDateStamp()
Then I reset the date to the first of the month with a little trick using the addCalendar function to actually subtract a calculated date from the current date.
ResetToFirstOfMonth = @DateTime.addCalendar(.CurrentDate,0,0,0,-(@DateTime.day(.CurrentDate) - 1),0,0,0)
Now I'll use the function again as intended and add 1 month to this. (Also note, I am passing the first manipulated date and not the current date this time. If you try to do it all in one shot, you'll need to consider a different algorithm)
AddOneMonth = @DateTime.addCalendar(.ResetToFirstOfMonth,0,1,0,0,0,0,0)
Here is the net effect.
-
Naresh RP
Infosys Limited
IN
Hi Rett,
How will it work for 12/**/2016?
While is Decmeber 2016 the property should show me 01/01/2017. So we need to add +1 to year also right?
thanks & Regards,
venugopal maddukuri.
Accepted Solution
Swedbank AB
SE
Hi Venugopal,
There's no need to add +1 to year, as the function will add 1 month to the current month and will update the year as well(only if it is december).
See the screenshot below for the test run:
- Test Activity
- Output for above activity
Let us know if this suffices your requirement.
Capgemini India Pvt Ltd
IN
Hi,
If I want to update present date to end of the month.
Ex:- if today date is 15/06/2016, the date should be update as 30/06/2016(30 or 31 based on the month)
Please share your inputs on thisimplementation.
Pegasystems Inc.
US
You can use the previous implementation with a small change to ResetToFirstOfMonth and changing the order of calculation. First add 1 month to the current date then subtract the number of the day of the month. In the previous implementation reset to first of the month was done taking day of the month - 1.
AddOneMonth = @DateTime.addCalendar(.CurrentDate,0,1,0,0,0,0,0)
LastOfMonth = @DateTime.addCalendar(.AddOneMonth,0,0,-(@DateTime.day(.AddOneMonth)),0,0,0)
Capgemini India Pvt Ltd
IN
Thanks Jeff, it is working :)
Infosys Limited
IN
Thanks singh & HEANR