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!
oh my god thank you! I didn´t see the missing ).
This seems to work now thank you all!
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))
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.
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)
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 😞
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)
@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().