cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
craigmk1987
Helper II
Helper II

Can I count between two dates?

Hello, is there an expression i can use to count the difference between these two dates?

craigmk1987_0-1602935537501.png

The full text of the dates are:

Start

formatDateTime(item()?['sharedTimeOff']?['startDateTime'], 'dd-MM-yyyy')

End

formatDateTime(item()?['sharedTimeOff']?['endDateTime'], 'dd-MM-yyyy')

 

1 ACCEPTED SOLUTION

Accepted Solutions
Pstork1
Dual Super User III
Dual Super User III

I did a quick POC and here is what I think is happening.  When the Time Off request is first submitted it is set to Pending and is in Draft mode.  While in Draft mode the Regular Start and End times are null, but there are start and end times in a DraftTimeOff object.  In your case the times are in a sharedTimeOff object.  So the actual JSON you want is below.

For approved instances  items('Apply_to_each')?['sharedTimeOff/startDateTime']
For draft instances   items('Apply_to_each')?['draftTimeOff/startDateTime']

Neither of them can be gotten from the trigger directly and they always come in a collection.  So they will always be accessed through a loop.  Here's my output.  You can see they are embedded in a draftTimeOff object.  If you look again at yours you'll see the SharedTimeOff object.

image.png



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

View solution in original post

9 REPLIES 9
Pstork1
Dual Super User III
Dual Super User III

Take a look at the solution in the following thread.  There is no direct function to determine the difference between two dates in Power Automate.  But you can use the Ticks() function to convert each date into Milliseconds after 01-01-1000 and then just subtract one from the other.  That will give you the difference in milliseconds.  You can then multiply that by a constant to get seconds, minutes, hours or whatever timespan you need.

https://powerusers.microsoft.com/t5/Building-Power-Apps/how-to-get-difference-between-two-dates-in-f... 



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Thank you for pointing me to that article. 

When trying to create the ticks, I'm hitting an error. I didn't mention before, but I'm trying to use a shift connector. The dates I am trying to access are Time Off Start Date & Time Off End Date. 

Using the following 

ticks(triggerBody()?['Time Off Start Time'])

Gives me an error of when using a compose variable

 Unable to process template language expressions in action 'Compose_-_Start_Time' inputs at line '1' and column '2844': 'The template language function 'ticks' expects its parameter to be a string that represents a timestamp. The provided value is of type 'Null'. Please see https://aka.ms/logicexpressions#ticks for usage details.'.

 

Any suggestions? Thank you!

Pstork1
Dual Super User III
Dual Super User III

I haven't used that particular connector yet, but to translate to Ticks() it needs to be a full date/time value in that format.  It looks like you are trying to use it on just the start time and not a full date and time.  The start time may also be coming through as a text field rather than a full date and time value.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Thank you for your reply - I appreciate your help in trying to help me solve my conundrum. 

interestingly the connector does provide the date in utc format

 

499E2E9C-2171-43B3-9F68-AC080E5289FE.jpeg

 but I can’t figure out how to “retrieve it” to compose the variables and put them together. 

Pstork1
Dual Super User III
Dual Super User III

What trigger are you using?  If its a SharePoint list then the correct code would be as follows for column called StartTime

Ticks(triggerOutputs()?['body/StartTime'])

 



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

I’m using the shifts triggers, specifically the “list all time off instances” trigger. When you run list all instances it gives the following outputs:

 

ED53ECCF-0152-4BBB-8845-915865E6EE07.jpeg

255A33C8-CE75-4C42-A756-6A7DA7000988.jpeg

AB706983-4595-47B1-8B4C-3BC9FA673B63.jpeg

 it’s this last photo where I’m trying to retrieve the date from so that I can try and build the ticks options that you suggested 🙂

Perhaps the way around it may be to build a SharePoint list that stores the information and then run the notification from there instead?

Pstork1
Dual Super User III
Dual Super User III

I did a quick POC and here is what I think is happening.  When the Time Off request is first submitted it is set to Pending and is in Draft mode.  While in Draft mode the Regular Start and End times are null, but there are start and end times in a DraftTimeOff object.  In your case the times are in a sharedTimeOff object.  So the actual JSON you want is below.

For approved instances  items('Apply_to_each')?['sharedTimeOff/startDateTime']
For draft instances   items('Apply_to_each')?['draftTimeOff/startDateTime']

Neither of them can be gotten from the trigger directly and they always come in a collection.  So they will always be accessed through a loop.  Here's my output.  You can see they are embedded in a draftTimeOff object.  If you look again at yours you'll see the SharedTimeOff object.

image.png



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

View solution in original post

Thank you so much for your help. 

 

I had hoped to find some time to post my final outcome - when I do get the chance, I will share my output. 

 

Thanks again!

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Users online (2,825)