cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
NurNina
Post Patron
Post Patron

Add 1 month to date

I have End date, and Extended date. Right now, I want to calculate Final Date.

 

If I have End date, I need to add a month to the date. If End date is empty, then I have to add a month to Extended date to get the final date. How do I do the flow? 

 

 

7 REPLIES 7
Expiscornovus
Super User
Super User

Hi @NurNina,

 

In the set variable of the Final Date field you could use if and empty functions in a expression to achieve this.

 

Below is an example:

if(empty(variables('EndDate')), addDays(variables('ExtendedDate'),30), addDays(variables('EndDate'),30))

 

setfinaldate.png

Hi @Expiscornovus ,

 

How about the months without 30 days?

Expiscornovus
Super User
Super User

Hi @NurNina,

 

If the end date is on the 5th you want the final date value to also be on the 5th the next month? Regardless if the month has less (working) days or even if it's a leap year?

 

If that's the case you should be able to use the addToTime function instead. Use this expression instead:

 

if(empty(variables('EndDate')), addToTime(variables('ExtendedDate'),1,'Month'), addToTime(variables('EndDate'),1,'Month'))

 

 

hi @Expiscornovus ,

thanks for the feedback. so addtoTime doesn't count the leap year is it? If I want to include leap year,there must be a calculation right? 

Expiscornovus
Super User
Super User

Hi @NurNina,

 

No that shouldn't be needed. The addToTime should also handle leap years. I have tested it with 12th of February 2020 and the Final Date is set as the 12th of March 2020.

 

finaldateleapyear.png

Hi @Expiscornovus, I've tried it,and it works perfectly for creating new data. However, when I try to trigger existing  record using the addtoTime, it doesn't give the correct result: 

 

NurNina_2-1608176478690.png

 

Final date:

NurNina_3-1608176625143.png

 

NurNina_4-1608176818660.png

 

 

 

 

 

Expiscornovus
Super User
Super User

Hi @NurNina,

 

It's not entirely clear what you are doing in your flow from the screenshots.

 

But I am assuming that you are looping through a set of end dates? If that's the case my guess would be that you also need to put that set variable 3 action within the first apply to each loop which contains the set variable action.

 

If the set variable 3 action is outside of the loop it will probably be only applied to your last date of record 69.

 

I hope that makes sense?

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Users online (2,332)