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

Count days between to dates

Hello,

I am quite new to Power Automate.
I need to get the difference between two dates and see, if it is more than 365. If so I want to do something otherwise I just do nothing.

I found this post:

https://powerusers.microsoft.com/t5/Building-Flows/Number-of-days-between-two-Dates/td-p/281578

 

and think this might be very helpful:

div(sub(ticks('2019-05-13'),ticks('2019-05-04')),864000000000)

 

Now my problem is to fill the date within the ticks-formula.
For the first date I use utcNow() which at least does not lead to a syntax error.

However I have difficulties setting the second date.
I tried to put it in a variable called "nextTermin".

So my expression looks like this:

 

 

 

div(sub(ticks('utcNow()'),ticks(variables('nextTermin')),864000000000)

 

 


 However Power Automate says the expression is invalid.
I also tried to put the string within the second ticks in quotation marks - ticks('variables('nextTermin')' but this does not work either.

Any help very appriciated.

Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions

I just checked the expression in editor, it's invalid because it's missing closing ) to close the div() expression.

div(sub(ticks(utcNow('yyyy-MM-dd')),ticks(formatDateTime(variables('nextTermin'),'yyyy-MM-dd')),864000000000))

 



[ If I have answered your question, please Accept the post as a solution. ]
[ If you like my response, please give it a Thumbs Up. ]

[ I also blog about Power Automate solutions even for non-IT people. ]

View solution in original post

7 REPLIES 7
krootz
Solution Supplier
Solution Supplier

@der_cosmicyes what's the type of variable 'nextTermin'? and can you share the value here? alternatively, if you just want to check if it's more than 365, I would just compare the year if they are not equal using formatdatetime().

tom_riha
Super User
Super User

Hello @der_cosmicyes ,

you shouldn't have the apostrophes around utcNow(). These tell the Power Automate that the content inside ' ' is a string = it'll not use the utcNow() as an expression, but as utcNow() text. Try to remove them.

div(sub(ticks(utcNow()),ticks(variables('nextTermin')),864000000000)

And maybe you'll need to convert both dates into the same format as in the example you shared.

div(sub(ticks(utcNow('yyyy-MM-dd')),ticks(formatDateTime(variables('nextTermin'),'yyyy-MM-dd')),864000000000)

 



[ If I have answered your question, please Accept the post as a solution. ]
[ If you like my response, please give it a Thumbs Up. ]

[ I also blog about Power Automate solutions even for non-IT people. ]

oh, thank you. That´s of course not what I want.
But then the problem is that if I remove the apostrophes it says again that the expression is invalid 😞

The original value is a date.
But I cannot assign type date to the variable so I choose String... that´s not ok I guess now.
The value is 01.01.2021 (german date)

hm, but the one date could be 31.12.2020 and the other could be 01.01.2021 - so the years are different but it is much less than 365 days.

I just checked the expression in editor, it's invalid because it's missing closing ) to close the div() expression.

div(sub(ticks(utcNow('yyyy-MM-dd')),ticks(formatDateTime(variables('nextTermin'),'yyyy-MM-dd')),864000000000))

 



[ If I have answered your question, please Accept the post as a solution. ]
[ If you like my response, please give it a Thumbs Up. ]

[ I also blog about Power Automate solutions even for non-IT people. ]

oh my god thank you! I didn´t see the missing ).
This seems to work now thank you all!

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 (5,040)