This is a review of how to find the time difference between two datetimes. The two methods I know use different expressions which will have different formats of outputs/results.
The dateDifference() expression - Output Result string d.hh:mm:ss.fffffff
dateDifference({StartDateTime},{EndDateTime})
Using ticks() expressions- Output Result is integer whole number
Days between datetimes using ticks:
div(sub(ticks({EndDateTime}),ticks({StartDateTime})),864000000000)
Hours between datetimes using ticks:
div(sub(ticks({EndDateTime}),ticks({StartDateTime})),36000000000)
Minutes between datetimes using ticks:
div(sub(ticks({EndDateTime}),ticks({StartDateTime})),600000000)
Seconds between datetimes using ticks:
div(sub(ticks({EndDateTime}),ticks({StartDateTime})),10000000)
Below I will describe:
The use of the dateDifference() expression is straight forward with only needing 2 values in a single expression. The expression will use a start datetime and end datetime with a string output of d.hh:mm:ss.fffffff which shows the combined amount of days, hours, minutes, seconds, and fractional seconds between the two datetimes.
Link to expression info below:
https://learn.microsoft.com/en-us/azure/logic-apps/workflow-definition-language-functions-reference#...
The expression below is what will be used:
dateDifference({start datetime},{end datetime})
Below is a flow example using a start datetime of May 1, 2023 12:00 PM and end datetime of May 4, 2023 11:30:15.45 AM which are put into separate variables (varStartTime and varEndTime). The variables are then used in an expression dateDifference(variables('varStartTime'),variables('varEndTime')) to find the time difference. The result difference output string is 2.23.30.15.4500000 where it is 2 days, 23 hours, 30 minutes, 15 seconds, and 45 hundredths of a second.
Below are some example output strings when using the dateDifference() expression.
Start Datetime | End Datetime | dateDifference() output string | Description |
May 1, 2023 12:00 PM | January 1, 2029 5:30 PM | 2072.05:30:00 | 2072 days. 5 hours: 30 minutes: 0 seconds |
May 1, 2023 12:00 PM | May 31, 2023 12:00 PM | 30.00:00:00 | 30 days. 0 hours: 0 minutes: 0 seconds |
May 1, 2023 12:00 PM | May 31, 2023 12:00:00.1 PM | 30.00:00:00.1000000 | 30 days. 0 hours: 0 minutes: 0 seconds. 1 tenth fractional second |
May 1, 2023 12:00 PM | May 4, 2023 10:00 PM | 3.10:00:00 | 3 days. 10 hours: 0 minutes: 0 seconds |
May 1, 2023 12:00 PM | May 4, 2023 11:30 AM | 2.23:30:00 | 2 days. 23 hours: 30 minutes: 0 seconds |
May 1, 2023 12:00 PM | May 2, 2023 10:00 PM | 1.10:00:00 | 1 day. 10 hours: 0 minutes: 0 seconds |
May 1, 2023 12:00 PM | May 2, 2023 12:00 PM | 1.00:00:00 | 1 day. 0 hours: 0 minutes: 0 seconds |
May 1, 2023 12:00 PM | May 2, 2023 11:30 AM | 23:30:00 | 23 hours: 30 minutes: 0 seconds |
May 1, 2023 12:00 PM | May 1, 2023 10:30 PM | 10:30:00 | 10 hours: 30 minutes: 0 seconds |
May 1, 2023 12:00 PM | May 1, 2023 12:30:35 PM | 00:30:35 | 0 hours: 30 minutes: 35 seconds |
May 1, 2023 12:00 PM | May 1, 2023 12:00:35 PM | 00:00:35 | 0 hours: 0 minutes: 35 seconds |
May 1, 2023 12:00 PM | May 1, 2023 12:00:00.08 PM | 00:00:00.0800000 | 0 hours: 0 minutes: 0 seconds. 8 hundredths fractional second |
May 1, 2023 12:00 PM | May 1, 2023 12:00 PM | 00:00:00 | 0 hours: 0 minutes: 0 seconds |
May 1, 2023 12:00 PM | May 1, 2023 10:30 AM | -01:30:00 | minus 1 hour: 30 minutes: 0 seconds |
May 1, 2023 12:00 PM | May 1, 2023 10:25:15 AM | -01:34:45 | minus 1 hour: 34 minutes: 45 seconds |
May 1, 2023 12:00 PM | May 1, 2023 10:20:05 AM | -01:39:55 | minus 1 hour: 39 minutes: 55 seconds |
May 1, 2023 12:00 PM | April 30, 2023 11:30 PM | -12:30:00 | minus 12 hours: 30 minutes: 0 seconds |
May 1, 2023 12:00 PM | April 30, 2023 12:00 PM | -1.00:00:00 | minus 1 day. 0 hours: 0 minutes: 0 seconds |
May 1, 2023 12:00 PM | April 30, 2023 10:30 AM | -1.01:30:00 | minus 1 day. 1 hour: 30 minutes: 0 seconds |
To use individual values from the output string of dateDifference() can be difficult due to the changing format and character count that is dependent upon the initial values.
dateDifference() Output String Format | Description |
d.hh:mm:ss | Equal to 24 hours OR more than 24 hours difference between start and end datetimes |
d.hh:mm:ss.fffffff | Equal to 24 hours OR more than 24 hours difference between start and end datetimes; at least one of the datetimes contains fractional seconds |
hh:mm:ss | Less than 24 hours difference between start and end datetimes |
hh:mm:ss.fffffff | Less than 24 hours difference between start and end datetimes; at least on of the datetimes contains fractional seconds |
-hh:mm:ss | Minus less than 24 hours difference between start and end datetimes |
-hh:mm:ss.fffffff | Minus less than 24 hours difference between start and end datetimes; at least one of the datetimes contains fractional seconds |
-d.hh:mm:ss | Minus more than 24 hours difference between start and end datetimes |
-d.hh:mm:ss.fffffff | Minus more than 24 hours difference between start and end datetimes; at least one of the datetimes contains fractional seconds |
In the two flow results from the photo below, I have a flow that is more than 24 hours difference between start and datetime, and a separate flow that is less than 24 hours difference between start and datetime. The output string of the dateDifference() expression has two different formats.
To extract a specific hour or minute value using expressions such as split() or first() that finds special characters such as '.' period or ':' colon will require knowing if the result will have a day value or fractional seconds to format the expression correctly.
The dateDifference() expression is a good tool for getting the difference between two datetimes into a readable string.
The use of the ticks() expression will convert a datetime into ticks. Ticks are are 100-nanosecond intervals, since January 1, 0001 12:00:00 midnight to the datetime. Basically the number of nanoseconds from January 1, 0001 to the datetime divided by 100 is the number of ticks. The ticks can be converted into days, hours, minutes, seconds, and fractional seconds by using the appropriate conversion number to divide by.
A tick is equal to 100 nanoseconds, or one ten-millionth of a second, which is seven decimal places after a second (00.0000001).
https://learn.microsoft.com/en-us/azure/logic-apps/workflow-definition-language-functions-reference#...
The expression is written as:
ticks({datetime})
The example flow below shows the ticks() expression used on a datetime of May 1, 2023 12:00 PM. The output result is the number of ticks that are between January 1, 0001 to May 1, 2023 12:00 PM. (This number of ticks would be the same as getting the number of nanoseconds between January 1, 0001 to May 1, 2023 12:00 PM and dividing that total amount of nanoseconds by 100.)
May 1, 2023 12:00 PM = 638,185,392,000,000,000 ticks
There are 638 quadrillion, 185 trillion, 392 billion ticks between January 1, 0001 to May 1, 2023
Knowing the datetime May 1, 2023 12:00 PM is the same as 638,185,392,000,000,000 ticks doesn't immediately help us much. The number is incredibly large and not in a normal term we would use. To get a better usage of the ticks number, we can convert it to something more understandable such as Days, Hours, Minutes, or Seconds by using a set conversion amount. (There is not a conversion amount in terms of years and months, both of which have a variable number of days.)
The table below shows how many ticks are within one of the corresponding time values. There are 864 billion ticks in a single day. There are 36 billion ticks in a single hour. If we consider there are 24 hours in a day and multiply the 36,000,000,000 ticks in a single hour by 24, the result is 864,000,000,000 which is the number of ticks in a single day.
Similarly, if we consider there are 60 minutes in an hour, we can divide the 36,000,000,000 ticks in a single hour by 60 the result is 600,000,000 which is the number of ticks in a single minute.
Time Value | Total Ticks Number | Total Ticks as Integer | Date Time Format d.hh:mm:ss.fffffff |
1 Day = 864 billion ticks | 864,000,000,000 | 864000000000 | 1.hh:mm:ss.fffffff |
1 Hour = 36 billion ticks | 36,000,000,000 | 36000000000 | d.01:mm:ss.fffffff |
1 Minute = 600 million ticks | 600,000,000 | 600000000 | d.hh:01:ss.fffffff |
1 Second = 10 million ticks | 10,000,000 | 10000000 | d.hh:mm:01.fffffff |
1 Decisecond = 1 million ticks | 1,000,000 | 1000000 | d.hh:mm:00.1 |
1 Centisecond = 100 thousand ticks | 100,000 | 100000 | d.hh:mm:00.01 |
1 Millisecond = 10 thousand ticks | 10,000 | 10000 | d.hh:mm:00.001 |
1 Microsecond = 10 ticks | 10 | 10 | d.hh:mm:00.000001 |
100 Nanoseconds = 1 tick | 1 | 1 | d.hh:mm:00.0000001 |
1 Nanosecond = 1/100 tick | 1/100 = 0.01 | 0.01 | d.hh:mm:00.000000001 |
In power automate you will use the div() expression to divide the number of ticks({DateTime}) by the conversion amount.
To Convert Ticks to Days divide by 864 billion:
div({ticks},864000000000)
To Convert Ticks to Hours divide by 36 billion:
div({ticks},36000000000)
To Convert Ticks to Minutes divide by 600 million:
div({ticks},600000000)
To Convert Ticks to Seconds divide by 10 million:
div({ticks},10000000)
Using the previous example to find the datetime May 1, 2023 12:00 PM is the same as 638,185,392,000,000,000 ticks. We can convert that tick quantity into different time values such as days, hours, minutes, or seconds. Remember this will be the total time difference between January 01, 0001 and May 1, 2023 12:00 PM.
Below is an example of converting ticks to Days, Hours, Minutes, and Seconds.
The output results show that the datetime May 1, 2023 12:00 PM is the same as 638,185,392,000,000,000 ticks. This number converted is the amount of time between May 1, 2023 12:00 PM and January 1, 0001 as days, hours, minutes, and seconds.
Most practical uses of ticks() will be to find the time difference between two datetimes. For example a request for an item is sent on May 1, 2023 at 12:00 PM and it was finally approved on May 4, 2023 at 11:30 AM and we want to know the amount of time the request was in process. We would convert both datetimes to ticks() and then subtract the Send (Start DateTime) from the Approval (End DateTime) to get the total difference of ticks between the two datetimes; then divide the difference in ticks by the conversion amount to get the total time difference as days, hours, or minutes.
In power automate we use the sub() subtract expression to subtract the number of ticks of the start datetime from the end date time. The End DateTime will have more ticks than the Start DateTime because it is further away from January 01, 0001. So the End DateTime should be the first (minuend) of the subtraction and the Start DateTime should be the second (subtrahend) of the subtraction EndDateTime - StartDateTime. Then divide this difference of ticks by the conversion time.
Days Between DateTimes using ticks:
div(sub(ticks({EndDateTime}),ticks({StartDateTime})),864000000000)
Hours Between DateTimes using ticks:
div(sub(ticks({EndDateTime}),ticks({StartDateTime})),36000000000)
Minutes Between DateTimes using ticks:
div(sub(ticks({EndDateTime}),ticks({StartDateTime})),600000000)
Seconds Between DateTimes using ticks:
div(sub(ticks({EndDateTime}),ticks({StartDateTime})),10000000)
Don't let the ticks() and nanoseconds references confuse you, this is basically simple Subtraction and Division.
Thought Example:
Now pretend the apples are actually datetime ticks(). Steve's apples will be ticks(End DateTime) and John's apples are ticks(Start DateTime). You subtract the two values to get the difference just like with the apples, except the values are ticks.
ticks(End DateTime) - ticks(Start DateTime) = TicksDifference
Then convert the TicksDifference into hours. Just like the easy division of converting minutes into hours, which is 60 minutes for 1 hour so Minutes/60 = Hours, you would use the number of ticks in 1 hour which is 36,000,000,000. So it will be TicksDifference/36,000,000,000 = Hours
Below is a flow example getting the total time values difference between two datetimes using ticks. The initialized variable varStartTime is the datetime May 1, 2023 12:00 PM. And the initialized variable varEndTime is May 4, 2023 11:30:15.45 AM.
Below is the time difference between May 1, 2023 at 12:00 PM and May 4, 2023 at 11:30 AM as Days: Result is 2
Below is the time difference between May 1, 2023 at 12:00 PM and May 4, 2023 at 11:30 AM as Hours: Result is 71
Below is the time difference between May 1, 2023 at 12:00 PM and May 4, 2023 at 11:30 AM as Minutes: Result is 4290
Below is the time difference between May 1, 2023 at 12:00 PM and May 4, 2023 at 11:30 AM as Seconds: Result is 257415
The output results show the total time values between May 1, 2023 12:00 PM and May 4, 2023 11:30:15.45 AM are as follows:
Note About Whole Number Results and Decimal Results:
The results of the previous expressions are whole number values and are not rounded. We know that the difference between the two datetimes is greater than 2 days, but since power automate div() expression does not add decimals if only using whole numbers, the output is only 2. To get a decimal value one or both of the factors in the div() expression needs to be a decimal which requires the use of the float() expression.
If we wrap each of the ticks({datetime}) values in a float() expression, it will return the results of each as a decimal value. That decimal value is then used in subtraction sub() expression which will also be decimal, and finally the division div() expression.
Days between DateTimes using ticks with decimal value output:
div(sub(float(ticks({EndDateTime})),float(ticks({StartDateTime}))),864000000000)
Hours between DateTimes using ticks with decimal value output:
div(sub(float(ticks({EndDateTime})),float(ticks({StartDateTime}))),36000000000)
Here are the same result of days and hours as the above but including the float() expression.
The decimal value output results show the total time values between May 1, 2023 12:00 PM and May 4, 2023 11:30:15.45 AM are as follows:
These outputs can be formatted further by using formatNumber() expression to determine a set amount of decimal places to return.
I know of two methods that will return the time value differences between two datetime values. The dateDifference() expression is a good tool that will return a string that is easier to read and understand. We can easily understand the dateDifference() string result of 2.23.30.15.45 as 2 days, 23 hours, 30 minutes, 15 seconds, and 45 hundredths of a second. However, this result is not as helpful if the time difference is needed in other steps to be added or calculated.
The use of the ticks() expression can seem complicated at first, but it is really just a way to get datetimes into a factor that can be calculated. When finding the difference between datetimes using the ticks() expression, the output will be a total time value that is either days, hours, minutes, or seconds as an integer. This value is easier to use in other steps where the time might need to be added or calculated with another value.
I hope this information helps or can be a reference, I will reply below with a way to extract values from the dateDifference() string.
Solved! Go to Solution.
Hi @wskinnermctc,
So detailed tutorial.👍
Thanks for your sharing.
Later, I will mark here to close this case so that other users who may have the similar issue could reach here dieectly.
Thanks for your cooperation.
Hi @wskinnermctc,
So detailed tutorial.👍
Thanks for your sharing.
Later, I will mark here to close this case so that other users who may have the similar issue could reach here dieectly.
Thanks for your cooperation.
Dear Community Members, We'd like to let you know of an upcoming change to the community platform: starting July 16th, the platform will transition to a READ ONLY mode until July 22nd. During this period, members will not be able to Kudo, Comment, or Reply to any posts. On July 22nd, please be on the lookout for a message sent to the email address registered on your community profile. This email is crucial as it will contain your unique code and link to register for the new platform encompassing all of the communities. What to Expect in the New Community: A more unified experience where all products, including Power Apps, Power Automate, Copilot Studio, and Power Pages, will be accessible from one community.Community Blogs that you can syndicate and link to for automatic updates. We appreciate your understanding and cooperation during this transition. Stay tuned for the exciting new features and a seamless community experience ahead!
We are excited to announce the Summer of Solutions Challenge! This challenge is kicking off on Monday, June 17th and will run for (4) weeks. The challenge is open to all Power Platform (Power Apps, Power Automate, Copilot Studio & Power Pages) community members. We invite you to participate in a quest to provide solutions to as many questions as you can. Answers can be provided in all the communities. Entry Period: This Challenge will consist of four weekly Entry Periods as follows (each an “Entry Period”) - 12:00 a.m. PT on June 17, 2024 – 11:59 p.m. PT on June 23, 2024 - 12:00 a.m. PT on June 24, 2024 – 11:59 p.m. PT on June 30, 2024 - 12:00 a.m. PT on July 1, 2024 – 11:59 p.m. PT on July 7, 2024 - 12:00 a.m. PT on July 8, 2024 – 11:59 p.m. PT on July 14, 2024 Entries will be eligible for the Entry Period in which they are received and will not carryover to subsequent weekly entry periods. You must enter into each weekly Entry Period separately. How to Enter: We invite you to participate in a quest to provide "Accepted Solutions" to as many questions as you can. Answers can be provided in all the communities. Users must provide a solution which can be an “Accepted Solution” in the Forums in all of the communities and there are no limits to the number of “Accepted Solutions” that a member can provide for entries in this challenge, but each entry must be substantially unique and different. Winner Selection and Prizes: At the end of each week, we will list the top ten (10) Community users which will consist of: 5 Community Members & 5 Super Users and they will advance to the final drawing. We will post each week in the News & Announcements the top 10 Solution providers. At the end of the challenge, we will add all of the top 10 weekly names and enter them into a random drawing. Then we will randomly select ten (10) winners (5 Community Members & 5 Super Users) from among all eligible entrants received across all weekly Entry Periods to receive the prize listed below. If a winner declines, we will draw again at random for the next winner. A user will only be able to win once overall. If they are drawn multiple times, another user will be drawn at random. Individuals will be contacted before the announcement with the opportunity to claim or deny the prize. Once all of the winners have been notified, we will post in the News & Announcements of each community with the list of winners. Each winner will receive one (1) Pass to the Power Platform Conference in Las Vegas, Sep. 18-20, 2024 ($1800 value). NOTE: Prize is for conference attendance only and any other costs such as airfare, lodging, transportation, and food are the sole responsibility of the winner. Tickets are not transferable to any other party or to next year’s event. ** PLEASE SEE THE ATTACHED RULES for this CHALLENGE** Week 1 Results: Congratulations to the Week 1 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Community MembersNumber SolutionsSuper UsersNumber Solutions Deenuji 9 @NathanAlvares24 17 @Anil_g 7 @ManishSolanki 13 @eetuRobo 5 @David_MA 10 @VishnuReddy1997 5 @SpongYe 9JhonatanOB19932 (tie) @Nived_Nambiar 8 @maltie 2 (tie) @PA-Noob 2 (tie) @LukeMcG 2 (tie) @tgut03 2 (tie) Week 2 Results: Congratulations to the Week 2 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 2: Community MembersSolutionsSuper UsersSolutionsPower Automate @Deenuji 12@ManishSolanki 19 @Anil_g 10 @NathanAlvares24 17 @VishnuReddy1997 6 @Expiscornovus 10 @Tjan 5 @Nived_Nambiar 10 @eetuRobo 3 @SudeepGhatakNZ 8 Week 3 Results: Congratulations to the Week 3 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 3:Community MembersSolutionsSuper UsersSolutionsPower Automate Deenuji32ManishSolanki55VishnuReddy199724NathanAlvares2444Anil_g22SudeepGhatakNZ40eetuRobo18Nived_Nambiar28Tjan8David_MA22 Week 4 Results: Congratulations to the Week 4 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 4:Community MembersSolutionsSuper UsersSolutionsPower Automate Deenuji11FLMike31Sayan11ManishSolanki16VishnuReddy199710creativeopinion14Akshansh-Sharma3SudeepGhatakNZ7claudiovc2CFernandes5 misc2Nived_Nambiar5 Usernametwice232rzaneti5 eetuRobo2 Anil_g2 SharonS2
On July 16, 2024, we published the 2024 release wave 2 plans for Microsoft Dynamics 365 and Microsoft Power Platform. These plans are a compilation of the new capabilities planned to be released between October 2024 to March 2025. This release introduces a wealth of new features designed to enhance customer understanding and improve overall user experience, showcasing our dedication to driving digital transformation for our customers and partners. The upcoming wave is centered around utilizing advanced AI and Microsoft Copilot technologies to enhance user productivity and streamline operations across diverse business applications. These enhancements include intelligent automation, AI-powered insights, and immersive user experiences that are designed to break down barriers between data, insights, and individuals. Watch a summary of the release highlights. Discover the latest features that empower organizations to operate more efficiently and adaptively. From AI-driven sales insights and customer service enhancements to predictive analytics in supply chain management and autonomous financial processes, the new capabilities enable businesses to proactively address challenges and capitalize on opportunities.
We're embarking on a journey to enhance your experience by transitioning to a new community platform. Our team has been diligently working to create a fresh community site, leveraging the very Dynamics 365 and Power Platform tools our community advocates for. We started this journey with transitioning Copilot Studio forums and blogs in June. The move marks the beginning of a new chapter, and we're eager for you to be a part of it. The rest of the Power Platform product sites will be moving over this summer. Stay tuned for more updates as we get closer to the launch. We can't wait to welcome you to our new community space, designed with you in mind. Let's connect, learn, and grow together. Here's to new beginnings and endless possibilities! If you have any questions, observations or concerns throughout this process please go to https://aka.ms/PPCommSupport. To stay up to date on the latest details of this migration and other important Community updates subscribe to our News and Announcements forums: Copilot Studio, Power Apps, Power Automate, Power Pages