How do I subtract two dates to find the hours between them when the dates are read in this format Dec 01 2021 12:19 PM AEST?
E.g. I would want Dec 02 2021 02:01 AM AEST - Dec 01 2021 12:19 PM AEST
Thank you in advance
Solved! Go to Solution.
Here is how you can do it. Change the difference unit as required.
Workflow:
Helpful reference document : https://help.alteryx.com/20213/designer/datetime-functions
Hope this helps : )
Hi @cayladuplooy ,
you should convert the date time input fields to a datetime data type first using the datetimeparse function:
DateTimeParse([F1], '%b %d %Y %I:%M %p')
In the next step, DateTimeDiff can return the difference in hours:
DateTimeDiff([DateTime1], [DateTime2], 'hours')
(assume, the converted fields are named "DateTime1" and "DateTime2")
Let me know if it works for you.
Best,
Roland
Thank you Roland, and this takes in to account AM and PM too as it includes %p? Is there a way to create the output with hours + minutes +seconds taken to match too? Example 01:40:00
Thank you, this works too 🙂
It looks like it does unless there hours taken is >24 then it does not calculate the correct number. For one scenario it look 55 hrs 30 mins so now it is giving me 7 hrs 30 mins. I assume the 48 hours is 2 days so it is cut off?
There is a workaround for it. Try this
The actual time can have 24hrs we need to treat it as a string to get more hours.
Hope this helps : )
Thank you so much 🙂
Happy to help : ) @cayladuplooy
Cheers and have a nice day!