Hello, is there an expression i can use to count the difference between these two dates?
The full text of the dates are:
Start
formatDateTime(item()?['sharedTimeOff']?['startDateTime'], 'dd-MM-yyyy')
End
formatDateTime(item()?['sharedTimeOff']?['endDateTime'], 'dd-MM-yyyy')
Solved! Go to Solution.
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.
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.
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.
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
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'])
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:
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.
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!
Join digitally, March 2–4, 2021 to explore new tech that's ready to implement. Experience the keynote in mixed reality through AltspaceVR!
User | Count |
---|---|
80 | |
55 | |
55 | |
43 | |
39 |
User | Count |
---|---|
84 | |
81 | |
76 | |
63 | |
42 |