4 Replies Latest reply on Jul 25, 2019 5:25 AM by Ronald Kaylor

# Calculate Time Difference ( In hours and Minutes )

Hi I am new to Tableau. Have a query. I have two fields in  excel, "First Status" and "Last Status". All rows in the column First Status is in the format 10-12-2014  9:29:27 AM. Same is the format for Last Status 11-12-2014  10:16:52 AM. I have to calculate Time Difference( In hours and Minutes only) between Last & First Status. Can a nyone help me out plz.

• ###### 1. Re: Calculate Time Difference ( In hours and Minutes )

Take a look at the datediff function

2 of 2 people found this helpful
• ###### 2. Re: Calculate Time Difference ( In hours and Minutes )

Old question but I had to do something similar at work today and here is what I came up with, maybe it can help out anyone that runs across this...

Assuming that both fields in your excel are date time types and not just strings, then you can use the following as a guide otherwise would have to convert the fields to dttm.
This function would return in a string format:

You'd replace Event Dttm UTC with "FIRST" and Cutin Dttm UTC with "LAST"

STR(CEILING(DATEDIFF('minute',[Event Dttm UTC],[Cutin Dttm UTC])/60)-1)+":"+

STR(DATEDIFF('minute',[Event Dttm UTC],[Cutin Dttm UTC]) -

((CEILING(DATEDIFF('minute',[Event Dttm UTC],[Cutin Dttm UTC])/60)-1) * 60 )

)

or if you need as decimal just change the colon to a dot and then wrap the entire function in a float:

FLOAT(STR(CEILING(DATEDIFF('minute',[Event Dttm UTC],[Cutin Dttm UTC])/60)-1)+"."+

STR(DATEDIFF('minute',[Event Dttm UTC],[Cutin Dttm UTC]) -

((CEILING(DATEDIFF('minute',[Event Dttm UTC],[Cutin Dttm UTC])/60)-1) * 60 )

))

If that helps then great, otherwise here is a good link:

2 of 2 people found this helpful
• ###### 3. Re: Calculate Time Difference ( In hours and Minutes )

Thank you for sharing the above.

Keep up the good work

• ###### 4. Re: Calculate Time Difference ( In hours and Minutes )

Thank you!  I am newer to Tableau and I was trying to solve this same issue. Thank you!