User Experience Insights
Calculate Closest Sunday’s Date to the 1st Date of Next Month
After a while, here I come with another useful piece of information to get the Closest Sunday’s Date to the 1st Date of Next Month.
The business rules functions have been used to get the desired results. This information may be customized to get other days of the month as well.
Background : I was implementing Pay Scale Progression for a manufacturing customer and the requirement was to create a wage pay increase record in Job and Compensation Information using off cycle batch event on the date of Closest Sunday to the 1st Date of Next Month.
How to achieve it: I created a business rule to be used in Off-Cycle event batch which in turn will create a record with the expected date of the next month.
Business Rule Functions used :
- Day of Week() : This function determines the number of the weekday for a given date. 1 stands for Monday, 7 for Sunday.
- Get First Day of the Month() : This function finds the first day of the same month as the month in the specified date.
- Date Plus() : With this function, you add or subtract a specified number of days or months to or from a given date.
- Day of Month() : This function determines the day of the month for a given date.
- Minus() : With this function, you can perform basic calculations for subtracting.
We used above functions to calculate the day of the Last Sunday of the current month and 1st Sunday of the next month.
We then compared the day of last Sunday of current month and first Sunday of next month. Whichever is lesser, we are setting that date to the effective date in Job and compensation information.
Steps to achieve the desired results:
2> Business Rule Variables for finding Numeric values for Last Sunday of current month:
4> Business Rule Variable to find the last date of the current month
5> As mentioned earlier, we are calculating numerical values of Last Sunday of Current Month and First Sunday of next month. Whichever is lesser means it is closer to the day 1 of the next month. We are calculating based on the condition passed in IF expression the event date as shown below.
I am sure this may be achieved in another way and maybe more optimal and efficient way as well. But I thought of sharing this to the community as I could not found a ready resource available when I was developing it and it might prove beneficial to few of you.
If you have done this in more efficient and optimal way, please do share!!