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 / Calculating number of ...
Power Automate
Suggested Answer

Calculating number of days elapsed

(1) ShareShare
ReportReport
Posted on by 77
Good day,
 
Kindly assist, I am trying to create a flow that calculates the number of days since the createdon date, for example, 2 days or 4 days since the createdon date. This is for my canvas app query management SLA. I need to escalate if no action taken in 2 days and in 4 days if there's no resolution. Initialize variable: addDays(utcNow(), -2) returns a string whereas createdon is date (Mismatch)
Categories:
I have the same question (0)
  • Suggested answer
    Sunil Kumar Pashikanti Profile Picture
    2,084 Moderator on at
     
    You are inside an Apply to each, you want to check:
         Whether DateClosed is empty
         And whether 2 or 4 days have passed since CreatedOn
     
    Step 1: Inside the Apply to each:
    Add a Compose step
    Name it: DaysElapsed
    Expression:
    int(
      div(
        sub(
          ticks(utcNow()),
          ticks(items('Apply_to_each')?['createdon'])
        ),
        864000000000
      )
    )
    Place this immediately under the Apply to each.
    This calculates whole days since createdon (UTC to UTC).
    No string/date mismatch, because ticks() works with DateTime directly.
    864000000000 = ticks per day.
     
    Step 2 — Replace your current Condition with this Condition
    Click Condition → Edit in advanced mode, then paste the relevant formula.
    Condition for Escalation Level 1 (2+ days, but less than 4): (please modify it as per your requirement)
    @and(
      empty(items('Apply_to_each')?['DateClosed']),
      greaterOrEquals(outputs('DaysElapsed'), 2),
      less(outputs('DaysElapsed'), 4)
    )
    If Yes → send Level 1 escalation email
    If No → check Level 2 condition
     
    Step 3 — Add a second Condition (for 4+ days)
    Expression:
    @and(Closed']),
      greaterOrEquals(outputs('DaysElapsed'), 4)
    )

    If Yes → send Level 2 escalation
    If No → do nothing
     
    ✅ If this answer helped resolve your issue, please mark it as Accepted so it can help others with the same problem.
    👍 Feel free to Like the post if you found it useful.
  • Suggested answer
    Kalathiya Profile Picture
    2,001 Super User 2026 Season 1 on at
    Hello @Petrusottie1
     
    Issue with using addDays(utcNow(), -2) directly is that Created On is a DateTime column, and each record can have a different time value. When you compare it with addDays(utcNow(), -2), you are comparing it to a single exact timestamp (the current time minus 2 days).

    Because of this, many records created on that day may not match exactly, which can lead to inconsistent results.

    In above suggestion, it’s partially correct in principle, but this will keep sending the escalation email every day for all records older than 4 days, unless you add a flag column to indicate that the escalation has already been sent. Also, practically this approach is not recommended, because every time the flow runs, it will retrieve all records and iterate through them to check the SLA. It’s more efficient to filter the records first so the flow only processes the relevant items for the escalation window.

    That’s why I suggested using a 24-hour date range filter, for example:
     
    This is for 4 days filter (Email)
    createdon ge '@{addDays(utcNow(), -4, 'yyyy-MM-ddT00:00:00z')}' and createdon lt '@{addDays(utcNow(), -4, 'yyyy-MM-ddT23:59:59z')}'
    
    //addDays(utcNow(), -4, 'yyyy-MM-ddT00:00:00z') - Put this in expression - First Expression
    //addDays(utcNow(), -4, 'yyyy-MM-ddT23:59:59z') - Put this in expression - Second Expression
    This is for 2 days filter (Email)
     
    createdon ge '@{addDays(utcNow(), -2 'yyyy-MM-ddT00:00:00z')}' and createdon lt '@{addDays(utcNow(), -2, 'yyyy-MM-ddT23:59:59z')}'
    
    //addDays(utcNow(), -2, 'yyyy-MM-ddT00:00:00z') - Put this in expression - First Expression
    //addDays(utcNow(), -2, 'yyyy-MM-ddT23:59:59z') - Put this in expression - Second Expression
     
    Also, if you use parallel actions for the 2-day and 4-day checks, both branches will run at the same time. This means the 2-day escalation and the 4-day escalation could execute in parallel, which may trigger both actions together depending on the condition.
     
     
    If this response resolves your issue, please mark it as the Verified Answer so it can help other community members as well.
    ---------------------------------------------------------------------------------
     
    📩 Need more help? Mention @Kalathiya anytime!
    ✔️ Don’t forget to Accept as Solution if this guidance worked for you.
    💛 Your Like motivates me to keep helping!
     
  • Petrusottie1 Profile Picture
    77 on at
    Hi @Kalathiya, Im getting this error  "The DateTimeOffset text '2026-03-09T00:00:00+00' should be in format 'yyyy-mm-ddThh:mm:ss('.'s+)?(zzzzzz)?' and each field value is within valid range." I tried changing it to 
    addDays(utcNow(), -2, 'yyyy-MM-ddT23:59:59+00') but still. 
  • Kalathiya Profile Picture
    2,001 Super User 2026 Season 1 on at
     
    It looks like the syntax that you have implemented is incorrectly.
     
    Just Past below expression in Dataverse action filter property: 
     
     
    This is for 4 days filter (Email)
    createdon ge '@{addDays(utcNow(), -4, 'yyyy-MM-ddT00:00:00z')}' and createdon lt '@{addDays(utcNow(), -4, 'yyyy-MM-ddT23:59:59z')}'
    This is for 2 days filter (Email)
    createdon ge '@{addDays(utcNow(), -2, 'yyyy-MM-ddT00:00:00z')}' and createdon lt '@{addDays(utcNow(), -2, 'yyyy-MM-ddT23:59:59z')}'
    
    If this response resolves your issue, please mark it as the Verified Answer so it can help other community members as well.
  • Petrusottie1 Profile Picture
    77 on at
    Hi @Kalathiya,
     
    Thank you. I've re-looked my syntax only to find the I was implement in a wrong way, but now I got it right. Thank so much once again.
  • Kalathiya Profile Picture
    2,001 Super User 2026 Season 1 on at
     
    Thanks for updating!
     

    If this solution helped, please mark it as the verified answer so it can help others in the community! 😊

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Vish WR Profile Picture

Vish WR 959

#2
Valantis Profile Picture

Valantis 872

#3
Haque Profile Picture

Haque 589

Last 30 days Overall leaderboard