Skip to main content
Nintex Community Menu Bar

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.

 

Start with Add Days 

25th of this month Step 1

Then drag Start of Month into first the input field

25th of this month Step 2

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

25th of this month Final Step

 

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.

 

Add 24 days 

25th of Last Month step 1

Calculate the Start of Last Month

25th Day of Last Month Step 2

By subtracting 1 day

25th Day of Last Month Step 3

From the Start of This Month

25 Day of Last Month Step 3

Substitute Current Date for your solution

25th Day of Last Month Final Step

 

3 Decide which date to use

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

Decide which date is the correct one

Below are the Expressions

All the expressions

Below are tests showing the expressions working.

Date < 25th​​​​
Date >= 25th​​​​​

 

I hope this helps


Reply