cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
annetoal
Advocate III
Advocate III

Date one year from date

Is there a way to add 1 year to a date? Not 365 days, because that will break every leap year. I understand addDays is the expression I would use.

 

Thanks,

Anne

4 ACCEPTED SOLUTIONS

Accepted Solutions
Pstork1
Dual Super User III
Dual Super User III

Use the AddToTime() function and use "Year" as the interval.  Its the generic version of AddDays().



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

View solution in original post

Paulie78
Super User III
Super User III

I think addDays would be more reliable than simply replacing the year, because if you just change the year, that day might not exist a year into the future. But anyway, you can just replace the year part of the date with the current year plus one, you could do it like this:

 

replace
(
    outputs('date'), 
    formatDateTime(utcNow(), 'yyyy'),
    string(add(int(formatDateTime(utcNow(), 'yyyy')),1))	
)

 

It just replaces the current year, with next year. I think I would still use addDays though.

 

Replied at the same time as @Pstork1 - his response is much better! 😂

View solution in original post

Pstork1
Dual Super User III
Dual Super User III

Calculate the date for a year in advance and then test it to find what day it is.  If its weekend add or subtract a day to get to Friday or Monday.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

View solution in original post

Pstork1
Dual Super User III
Dual Super User III

I did some testing and it will work even if the input date is 2/29 in Leap year.  But it doesn't seem very sophisticated.  If I input 2/29/2024 and add a year I get 2/28/2025.  If I add 4 years I get 2/29/2028.  So it only deals with Leap year when processing Leap Day.  Otherwise it basically just changes the year.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

View solution in original post

6 REPLIES 6
Pstork1
Dual Super User III
Dual Super User III

Use the AddToTime() function and use "Year" as the interval.  Its the generic version of AddDays().



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

View solution in original post

Paulie78
Super User III
Super User III

I think addDays would be more reliable than simply replacing the year, because if you just change the year, that day might not exist a year into the future. But anyway, you can just replace the year part of the date with the current year plus one, you could do it like this:

 

replace
(
    outputs('date'), 
    formatDateTime(utcNow(), 'yyyy'),
    string(add(int(formatDateTime(utcNow(), 'yyyy')),1))	
)

 

It just replaces the current year, with next year. I think I would still use addDays though.

 

Replied at the same time as @Pstork1 - his response is much better! 😂

View solution in original post

Thanks! Now a follow-up question: is there a way to force the date 1 year in the future to be the nearest weekday? In other words, if the date 1 year in the future falls on a weekend, it would show the Friday or Monday closest to that day. Any help greatly appreciated.

 

Anne

Would that break if the date was calculated one year from Leap Day?

 

Anne

Pstork1
Dual Super User III
Dual Super User III

Calculate the date for a year in advance and then test it to find what day it is.  If its weekend add or subtract a day to get to Friday or Monday.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

View solution in original post

Pstork1
Dual Super User III
Dual Super User III

I did some testing and it will work even if the input date is 2/29 in Leap year.  But it doesn't seem very sophisticated.  If I input 2/29/2024 and add a year I get 2/28/2025.  If I add 4 years I get 2/29/2028.  So it only deals with Leap year when processing Leap Day.  Otherwise it basically just changes the year.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

View solution in original post

Helpful resources

Announcements
MPA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MSFTBizAppsLaunchEvent

Experience what’s next for Power Virtual Agents

See the latest Power Automate innovations, updates, and demos from the Microsoft Business Applications Launch Event.

New Super Users

Meet the Power Automate Super Users!

Many congratulations to the Season 1 2021 Flownaut Crew!

Power Platform ISV STudio

Power Platform ISV Studio

ISV Studio is the go-to Power Platform destination for ISV’s to monitor & manage applications post-AppSource publish.

Users online (30,919)