cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
leyburn19
Memorable Member
Memorable Member

Subtract dates

I want to subtract one date from another to get an integer result

 

I have a sharepoint list that I want to use update item  to update a number column based two other date columns.  At the moment I have tried placing an expression in teh field to be updated like sub(int('Dateto'),int('DateFrom')) but this fails.

 

Is there a way to do this?

1 ACCEPTED SOLUTION

Accepted Solutions

OK I solved this with the following flow:

 

 flow.PNG

 

Variable one expression is

 

ticks(triggerBody()?['DateFrom'])

 

Variable 2 expression is

 

ticks(triggerBody()?['DateTo'])

 

Variable 3 Expression is

 

div(sub(variables('Test2'),variables('Test')),864000000000)

 

So variable 3 gives me the result in teh number of days so that I can update the Days field in SharePoint List

 

The email is simply a way for me to monitor the process

View solution in original post

6 REPLIES 6
v-yuazh-msft
Community Support
Community Support

Hi @leyburn19,

 

You couldn't use the sub() expression to calculate the number of days difference between two dates.

Does the Dateto and DateFrom are in the same year?

 

If the Dateto and DateFrom are in the same year, you could use expression below to achieve your needs:

sub(dayOfYear(Dateto),dayOfYear(DateFrom))

You could refer to link below to learn more about the workflow definition language:

https://docs.microsoft.com/en-us/azure/logic-apps/logic-apps-workflow-definition-language

 

 

If the Dateto and DateFrom are not in the same year,I afraid that it is difficult to calculate the number of days difference between two dates in microsoft flow currently.

 

If you would like a function to calculate the number of days difference between two dates to be supported in microsoft flow, please submit an idea to Flow Ideas Forum:

https://powerusers.microsoft.com/t5/Flow-Ideas/idb-p/FlowIdeas

 

 

Best regards,

Alice

 

Yes I think a datediff function is really necessary.  That said I am exploring the Ticks().  I create two integer variables and in each one put the a tick formula

 

 

Variable 1   ticks(body('Get_item')?['DateFrom']) 

Variable 2   ticks(body('Get_item')?['DateTo'])

 

When I subtract one from the other I should get a ticks result that can be be divided by the number of ticks in a day leaving a result that should be correct.

 

I am currently stuck on the latter.  I thought a third variable but fails,  so I tried a compose but this has failed as well

OK I solved this with the following flow:

 

 flow.PNG

 

Variable one expression is

 

ticks(triggerBody()?['DateFrom'])

 

Variable 2 expression is

 

ticks(triggerBody()?['DateTo'])

 

Variable 3 Expression is

 

div(sub(variables('Test2'),variables('Test')),864000000000)

 

So variable 3 gives me the result in teh number of days so that I can update the Days field in SharePoint List

 

The email is simply a way for me to monitor the process

Anonymous
Not applicable

I think it's easier to use DATEDIF as a calculated third column in the list itself.

I needed this recently and I ended up adapting your solution to account for years.

 

add(mul(365,sub(int(formatDateTime(utcNow(),'yyyy')),int(formatDateTime(pastDate,'yyyy')))),sub(dayOfYear(utcNow()),dayOfYear(pastDate)))
 
This doesn't account for leap years but was good enough for my needs.
 
Hope this might be useful to someone.

Alice,

HI - 

I have successfully  posted in Powerapps forums, but appear unable to post to the link you provided, and I am signed in.  How to I vote to get this function you mention added as an internal function?  Thanks

 

Link:  https://powerusers.microsoft.com/t5/Flow-Ideas/idb-p/FlowIdeas

 

 

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

Power Automate Designer Feedback_carousel.jpg

Help make Flow Design easier

Are you new to designing flows? What is your biggest struggle with Power Automate Designer? Help us make it more user friendly!

Users online (1,851)