Question

calculate the 25th day of every month based on the current date

• 2 replies
• 240 views

I have to calculate the 25th day of every month based on the current date, with the following requirements:

1. If the current date is on or after the 25th day of the month, then return the 25th day of the current month.

2. If the current date is before the 25th day of the month, then return the 25th day of the previous month.

I am looking for an expression that dynamically calculates and returns the date, ensuring it always falls on the 25th day based on the current date.

So I have to get the 25th of every month based on current date in the From date calendar control.
Trying to achieve it through expressions.

Please let me know if you ahve any other approach for it.

From Date Expression: Add Days ( Start Of Month ( Subtract Days ( Start Of Month ( Current Date ) , 1 ) ) , 22 )

To Date Expression: Add Days ( Start Of Month ( Current Date ) , 21 )

Hi Nagma_Nk

In my example I have used a calendar control as this made testing easier, for your purpose just substitute the calendar control for the current date

I have broken the problem into 3 steps.

1. Calculate the 25th of this month
2. Calculate the 25th of last month
3. Decide which one is appropriate

Below are the detailed steps.

1. Calculate 25th of this month

We calculate the start of this month using the Start Of Month function.

Then Add 24 days to get to the 25th day of the month using the Add Days function

When working with expressions I find it easiest to build them from the outer most function inwards.

Then drag Start of Month into first the input field

Lastly drag the date into the input for the Start of Month function (substitute current date for your solution).

2. Calculate the 25th day of last Month (read this one a couple of times if you need to)

With the functions we have available my calculations are broken down below.

Start of this month (Calendar) - 1 Day = End of Last Month

Start of Month (End of Last Month) = Start of Last Month

Start of Last Month + 24 Days = 25th day of Last Month

I used Add Days and passed in -1, but this can be replaced by Subtract Days instead.

Taking the same outer most to Inner most approach as before.

Calculate the Start of Last Month

By subtracting 1 day

From the Start of This Month

Substitute Current Date for your solution

3 Decide which date to use

Now base on the current date choose which value to use using logical operators

Below are the Expressions

Below are tests showing the expressions working.

I hope this helps