cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
silkwire
Helper I
Helper I

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
ScottShearer
Super User
Super User

@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

View solution in original post

7 REPLIES 7
ScottShearer
Super User
Super User

@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

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.

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.

@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

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. 

takolota
Community Champion
Community Champion

takolota
Community Champion
Community Champion

….

Helpful resources

Announcements
Power Automate News & Announcements

Power Automate News & Announcements

Keep up to date with current events and community announcements in the Power Automate community.

Community Calls Conversations

Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Automate Community Blog

Power Automate Community Blog

Check out the latest Community Blog from the community!

Users online (2,379)