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 / Subtract two dates and...
Power Automate
Unanswered

Subtract two dates and times

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hello everyone,

 

I want to subtract two dates from each other, but I get this error:

mtndnmz_0-1682511656903.png

The format I use to subtract dates is like this: div(sub(ticks(formatDateTime(addHours(utcNow(),3)),'yyyy-MM-ddTHH:mm:ss')),ticks(formatDateTime(item()?[ 'X'])),'yyyy-MM-ddTHH:mm:ss'),864000000000)

Categories:
I have the same question (0)
  • annetoal Profile Picture
    1,934 Moderator on at

    Can't read your error message--

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    The error I get is as follows:

    Unable to process template language expressions in action 'Compose_2' inputs at line '0' and column '0': 'In function 'formatDateTime', the value provided for date time string '20230426 000900.000' was not valid. The datetime string must match ISO 8601 format.'.

  • annetoal Profile Picture
    1,934 Moderator on at

    How do you want the datetime to appear?

     

     

     

     

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    In order for me to subtract two dates from each other, I guess they have to be equal. I use the format yyyy-MM-ddTHH:mm:ss in the utcNow function I use for the first date. On my second date, the data I received is 20230426 000900.000. I guess I should parse it first, but I was unsuccessful.

  • annetoal Profile Picture
    1,934 Moderator on at

    Try this instead

    formatDateTime(utcNow(),'d MMM yyyy hh:mm:ss tt')

    Substituting whatever time string you need for where I put utcNow().

     

    If this helped, please mark it as a Solution,

    Anne

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    I am still getting the same error. I guess the problem is not where I use utcNow, but in the time zone of the data that I use as the 2nd date.

  • David_MA Profile Picture
    14,054 Super User 2026 Season 1 on at

    I suspect you are trying to determine the difference in time between two dates rather than actually subtracting one from the other. If this is the case, the following expression will tell you how many days have elapsed between the Created and Modified dates:

     

    div(sub(ticks(formatDateTime(triggerBody()?['Modified'],'yyyy-MM-dd')),ticks(formatDateTime(triggerBody()?['Created'],'yyyy-MM-dd'))),864000000000)

     

    This is a good blog post (How to calculate difference between two times in Power Automate (tomriha.com)) to show you how to get days, hours, minutes and seconds between two dates.

     

    If you just want to subtract x number of days from a date, you would use the addDays expression and enter a negative number:

     

    addDays(items('Apply_to_each')?['Modified'],-3,'yyyy-MM-dd')

     

     

     There are expressions for addHours, addMinutes and addSeconds as well. If you want to subtract, use a negative number.

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    I need to get the difference not only in date but also in hours and minutes. If there is more than 30 minutes between the current date and the current date for each item, I will process them. Do I need to do the formula you mentioned in the first paragraph in hours and minutes?

  • Phonic_Shihawu2 Profile Picture
    14 on at

    Add a "Compose" action to your flow.
    In the "Inputs" field of the "Compose" action, add the following expression:
    subtractFromTime(utcNow(), variables('startDate'), 'HH:mm')

    Replace "variables('startDate')" with the date you want to subtract from (e.g. a SharePoint column that contains a date/time value).
    3. The result of the "Compose" action will be the time difference between the two dates in the format "HH:mm". You can then use this value in other actions in your flow.

  • David_MA Profile Picture
    14,054 Super User 2026 Season 1 on at

    The blog post I posted (How to calculate difference between two times in Power Automate (tomriha.com)) will show you what you need to do. The calculation can only calculate it to one thing, either days, hours, minutes OR seconds. Since you need to know if it has been more than 30 minutes, use the minutes calculation and you can use it in a condition to see if the result is greater than 30.

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!

Leaderboard > Power Automate

#1
Haque Profile Picture

Haque 523

#2
Valantis Profile Picture

Valantis 318

#3
David_MA Profile Picture

David_MA 235 Super User 2026 Season 1

Last 30 days Overall leaderboard