Tuesday, 06 April 2021 07:06

## Calculate Closest Sunday’s Date to the 1st Date of Next Month

Written by Jitendra Kumar
Rate this item
Source https://blogs.sap.com/2021/04/07/calculate-closest-sundays-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.

• 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:

1> Business Rule Variables for finding Numeric values for First Sunday of next month:

2> Business Rule Variables for finding Numeric values for Last Sunday of current month:

3> Business Rule Variable to find the first date of the next 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