web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Find days to future da...
Power Automate
Answered

Find days to future date - I don't understand the math

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

I have a SharePoint column called "ExpirationDate."  My workflow counts the days to the date.  Everything seems to work except the positive results appear to be off by a day.  I thought I understood that because I just figured the end date wasn't counted, but when I get the same result (0) on two different dates . . . I just don't understand the math.

 

Here is my expression:

div(sub(ticks(items('Apply_to_each_item')['ExpirationDate']),ticks(utcNow())),864000000000)

 

Today is 7/6/2022 and I get the following results for each expiration date:

 

ExpirationDate 7/5/22 results in -1 days (perfect)

ExpirationDate 7/6/22 results in 0 days (perfect)

ExpirationDate 7/7/22 also results in 0 days (Huh?  0 twice?  Should be 1.)

ExpirationDate 7/8/22 results in 1 day (should be 2 and so on)

 

How can two different dates result in the same value using the exact same math function?  I can't even add a condition that if the result is greater than or equal to 0 then subtract a day because I get 0 on two different days.

 

Can someone please help me with the math here before my brain explodes?

Categories:
I have the same question (0)
  • ScottShearer Profile Picture
    25,290 Most Valuable Professional on at

    Does your expiration date include the time?  This might be a time zone issue.

     

  • Verified answer
    Community Power Platform Member Profile Picture
    Microsoft Employee on at

    I was able to figure this out myself.  Not sure if this is the most efficient way or not, but I'll outline it . . .

     

    To find the number of days between today and the ExpirationDate value, I was subtracting utcNow().  However, utcNow() will always have the current timestamp, and my date column had zeros (date only column).  Original expression: div(sub(ticks(items('Apply_to_each_item')['ExpirationDate']),ticks(utcNow())),864000000000)

     

    To fix this I formatted utcNow() to just the date: formatDateTime(utcNow(),'yyyy-MM-dd')

    Then I formatted that result to round-trip date pattern (but I think it could have been any pattern with time): formatDateTime(formatDateTime(utcNow(),'yyyy-MM-dd'),'O')

    Then I converted to ticks: ticks(formatDateTime(formatDateTime(utcNow(),'yyyy-MM-dd'),'O')) and plugged it in where I originally had ticks(utcNow()).

     

    So the full revised expression is:  

    div(sub(ticks(outputs('Get_item')?['body/Date']),ticks(formatDateTime(formatDateTime(utcNow(),'yyyy-MM-dd'),'O'))),864000000000)

     

    My new result is:

     

    Today is 7/6/2022 and I get the following results for each expiration date:

     

    ExpirationDate 7/5/22 results in -1 days

    ExpirationDate 7/6/22 results in 0 days

    ExpirationDate 7/7/22 results in 1 day 

    ExpirationDate 7/8/22 results in 2 days

     

     

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Yes, thank you.  I was actually posting my solution as you were replying.  Thank you!

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    UPDATE:

     

    For anyone having this issue, I am posting a correction to my solution.  I had to also format the expiration date as well as the utcNow() date.  I didn't think it would be necessary since it is a date only column, so the time default is midnight, but it seems I do.  For an apples-to-apples comparison, and to get the correct value, format both dates in the same manner.

     

    My revised expression is:

     

    div(sub(ticks((formatDateTime(formatDateTime(outputs('Get_item')?['body/Date'],'yyyy-MM-dd'),'O')),ticks(formatDateTime(formatDateTime(utcNow(),'yyyy-MM-dd'),'O'))),864000000000)

     

    Hopefully this one sticks.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Valantis Profile Picture

Valantis 412

#2
Vish WR Profile Picture

Vish WR 305

#3
David_MA Profile Picture

David_MA 262 Super User 2026 Season 1

Last 30 days Overall leaderboard