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

Notifications

Announcements

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

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
    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
    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
    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
    12,982 Super User 2025 Season 2 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
    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
    12,982 Super User 2025 Season 2 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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 519 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 296 Moderator

#3
abm abm Profile Picture

abm abm 232 Most Valuable Professional

Last 30 days Overall leaderboard