cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
silkwire
Level: Powered On

Issue with AddToTime

I am dynamically patching rows into a SQL table based on how many months there are between a starting date and ending date. I've got almost everything working nicely except for the AddToTime calculation in Flow.

 

This is my current formula that runs in a loop until the counter hits the required number of months: 

addToTime(variables('startingMonth'), variables('counter'), 'Month') 

 

I want the entry to be the first of every month. I pass in startingMonth as a date that is the first of a month. It seems adding a month only adds 4 weeks though... which is kind of understandable, but this screws me up in the month of June. One entry is for 6/1/2019, and the next is for 6/29/19. 

 

There is a function in PowerApps called DateAdd() that works as I desire, but I'm not able to dynamically build a table with looping in PowerApps, so I need to build it in Flow.

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Super User
Super User

Re: Issue with AddToTime

@silkwire 

This shouldn't be hard.......

Please see my screen shots below.  I could have combined all of my variables into one really ugly nested expression but I left as is for the sake of readability.

I use utcNow as my staring point, but any date/time should work if formatted as yyyy-MM-dd.

My expresssions are in the comments at the top of each action.

 

NextMonth1.jpgNextMonth2.jpg

 

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

Scott
5 REPLIES 5
Highlighted
Super User
Super User

Re: Issue with AddToTime

@silkwire 

This shouldn't be hard.......

Please see my screen shots below.  I could have combined all of my variables into one really ugly nested expression but I left as is for the sake of readability.

I use utcNow as my staring point, but any date/time should work if formatted as yyyy-MM-dd.

My expresssions are in the comments at the top of each action.

 

NextMonth1.jpgNextMonth2.jpg

 

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

Scott
silkwire
Level: Powered On

Re: Issue with AddToTime

I appreciate your help. It doesn't quiiite do the trick though. What about if next month is in next year?

 

I just wish addToTime worked like DateAdd in PowerApps :/ much more useful.

silkwire
Level: Powered On

Re: Issue with AddToTime

addToTime(utcnow(), 4, 'Week') will add four weeks.

 

addToTime(utcnow(), 1, 'Month') should jump to the next month, not just be a different way of saying add four weeks.

Super User
Super User

Re: Issue with AddToTime

@silkwire :

 

I agree - I missed the end of year issue with month.  That said, that can be fixed with a simple if expression.

 

I also agree that this should be simple.......

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

Scott
silkwire
Level: Powered On

Re: Issue with AddToTime

Thanks for the help! I will mark your first response as the solution.

 

I ended up solving in PowerApps itself by creating a manual collection and building future dates with DateAdd() with an additional counter column that my If statement checks against to see if it should Patch the new row. 

Helpful resources

Announcements
firstImage

Microsoft Business Applications Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

Power Platform 2019 Release Wave 2 Plan

Power Platform 2019 Release Wave 2 Plan

Features releasing from October 2019 through March 2020

thirdimage

Flow Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

fifthimage

Microsoft Learn

Learn how to build the business apps that you need

sixthImage

Power Platform World Tour

Find out where you can attend!

seventhimage

Webinars & Video Gallery

Watch & learn from the Flow Community Video Gallery!

Users Online
Currently online: 235 members 4,350 guests
Please welcome our newest community members: