8 Replies Latest reply on Mar 26, 2020 12:55 PM by Don Wise

# Time and Date different between 2 columns.

Hi folks,

Can someone explain to me how to calculate the difference between two-time points?

Let's say I have a table from the SQL server that has columns that are showing the date/time of an event:  EventID, EventStartDate, EventEndDate, EventStartTime, EventEndTime.

Now I would like to know how long did events happen, EventDurationDay = EventEndDate - EventStartDate, EventDurationMinuter = EventEndTime - EventStartTime.

• ###### 1. Re: Time and Date different between 2 columns.

Hi Kyle,

The answer really depends on how your data is structured.  Without knowing that there could be at least two or more answers for you.  Can you supply/attach a small set of either real or mock data in order for your question to get more attention?

As you note the time is between two columns, right now a DATEDIFF ('minute',[EventStartDate],[EventEndDate]) would be the calculation I'd attempt to use.

Best, Don

1 of 1 people found this helpful
• ###### 2. Re: Time and Date different between 2 columns.

Hey Don, thank for your help.

I attached the data in this reply

• ###### 3. Re: Time and Date different between 2 columns.

Hi Kyle,

Thanks, but you'll need to attach a packaged workbook with a file extension of .twbx.  A .twb workbook only brings in the structure of the workbook and not the actual data.  Best, Don

Packaged Workbooks - When, How, Why

https://community.tableau.com/docs/DOC-8982

Attaching a Packaged Workbook

https://community.tableau.com/docs/DOC-5743

• ###### 4. Re: Time and Date different between 2 columns.

To make it fast and simple

Much appreciated.

Do you think I need to warp eventStartDate and eventStartTime into one column? Also, how can I count how many events are more than 5 days?

• ###### 5. Re: Time and Date different between 2 columns.

Hi Kyle,

I looked through the thread but don't see the packaged workbook. D

• ###### 6. Re: Time and Date different between 2 columns.

It's so weird.

Anw, I re-attached the tables to show you how data look like in this rep.

• ###### 7. Re: Time and Date different between 2 columns.

Hey Don,

DATEDIFF is working and help me in this case.

My solution is using SQL to cast eventDate and eventTime into one new column eventDateTime. So, from 4 tables to just two tables. THen calculate different in minutes from there.

I don't want to open a new discussion, but is there any way I can count how many eventID(rows) at different times which is more than 2 days?