Inspire EMEA 2022 On-Demand is live! Watch now, and be sure to save the date for Inspire 2023 in Las Vegas next May.
alteryx Community

# Alteryx Designer Discussions

SOLVED

## Calculation between two dates with AM/PM

8 - Asteroid

Hi,

I want to calculate the difference in time(in minutes) between two dates. My dates are as attached

i want to see the total difference in minutes between  Completion_Time and Complete_Before.

If Completion_Time is after the  Complete_Before then return "Late"

if Completion_Time is before the  Complete_Before then return "Early"

The tricky part is with the AM/PM part.

10 REPLIES 10
16 - Nebula

The following should do the trick @mboroto_89: - have attached the workflow too:

``DateTimeDiff(DateTimeParse([Complete_Before], '%d %b %Y %I:%M:%S %p'),DateTimeParse([Completion_Time], '%d %b %Y %I:%M:%S %p'),'minute')``

If you just want the raw difference, without negatives, then wrap it in abs(), like so:

``abs(DateTimeDiff(DateTimeParse([Complete_Before], '%d %b %Y %I:%M:%S %p'),DateTimeParse([Completion_Time], '%d %b %Y %I:%M:%S %p'),'minute'))``

And for the Early/Late flag, you can use:

``if DateTimeParse([Completion_Time], '%d %b %Y %I:%M:%S %p') > DateTimeParse([Complete_Before], '%d %b %Y %I:%M:%S %p') then 'Late' else 'Early' endif``

8 - Asteroid

Hello,

here is how I would do it:

Workflow is attached as well

8 - Asteroid

Thanks @DataNath @AlexEntz both solutions work!

Thanks for the swift response..much appreciated.

8 - Asteroid

Thanks @AlexEntz the new dates will also play a role in my workflow, many thanks!

17 - Castor

@mboroto_89, is another way to solve this problem. I hope this helps!

Thanks!

Sapna Gupta
8 - Asteroid

Thanks @grazitti_sapna this works as well

17 - Castor

@mboroto_89 , thanks and glad it worked.

Sapna Gupta
8 - Asteroid

@DataNath @AlexEntz @grazitti_sapna using the Complete Before Column, are we able to get which day of the week this was? e.g Monday/Saturday?

17 - Castor

@mboroto_89  this formula will help, DateTimeFormat([New Value ],"%A"). Just replace new value with the complete_before field.

Sapna Gupta
Labels