cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
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

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
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!

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. 

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?

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
Microsoft Ignite

Microsoft Ignite

Join digitally, March 2–4, 2021 to explore new tech that's ready to implement. Experience the keynote in mixed reality through AltspaceVR!

New Super Users

Meet the Power Automate Super Users!

Many congratulations to the Season 1 2021 Flownaut Crew!

New Badges

New Solution Badges!

Check out our new profile badges recognizing authored solutions!

MPA Community Blog

Power Automate Community Blog

Check out the community blog page where you can find valuable learning material from community and product team members!

Users online (25,835)