Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
SOLVED

Date Calculations

cayladuplooy
7 - Meteor

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

9 REPLIES 9
atcodedog05
22 - Nova
22 - Nova

Hi @cayladuplooy 

 

Here is how you can do it. Change the difference unit as required.

Workflow:

atcodedog05_0-1641808519955.png

 

Helpful reference document : https://help.alteryx.com/20213/designer/datetime-functions 

 

Hope this helps : )

 

RolandSchubert
16 - Nebula
16 - Nebula

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

 

 

 

cayladuplooy
7 - Meteor

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

cayladuplooy
7 - Meteor

Thank you, this works too 🙂

atcodedog05
22 - Nova
22 - Nova

Hi @cayladuplooy 

 

Are you looking for something like below

 

Workflow:

atcodedog05_0-1641809167530.png

 

Hope this helps : )

 

cayladuplooy
7 - Meteor

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?

atcodedog05
22 - Nova
22 - Nova

Hi @cayladuplooy 

 

There is a workaround for it. Try this

 

atcodedog05_0-1641809933679.png

 

The actual time can have 24hrs we need to treat it as a string to get more hours.

 

Hope this helps : )

 

cayladuplooy
7 - Meteor

Thank you so much 🙂

atcodedog05
22 - Nova
22 - Nova

Happy to help : ) @cayladuplooy 

Cheers and have a nice day!

Polls
We’re dying to get your help in determining what the new profile picture frame should be this Halloween. Cast your vote and help us haunt the Community with the best spooky character.
Don’t ghost us—pick your favorite now!
Labels