Fluorite | Level 6

## Finding the "time since" in minutes for date and time

I am trying to find the difference in minutes between two events. I have two variables for time and two variables for dates. I first tried both the INTCK function and FLOOR function, which worked well to find the difference in minutes between my time variables. However, this does not account for date changes.

For example, in finding the time between Onset and Randomization:

For Subject 1 -

OnsetDate is 2011-05-15 and OnsetTime is 15:00:00.

RandomizationDate is 2011-05-15 and RandomizationTime is 17:36:00.

This leaves 156 minutes between Onset and Randomization.

For Subject 2 -

OnsetDate is 2011-06-27 and OnsetTime is 21:55:00.

RandomizationDate is 2011-06-28 and RandomizationTime is 00:35:00.

I need a function that can account for this date change when finding the time difference.

1 ACCEPTED SOLUTION

Accepted Solutions
Super User

## Re: Finding the "time since" in minutes for date and time

Create complete timestamps (datetime values) out of your variables first:

``onset_ts = dhms(onset_date,0,0,onset_time);``

Then you can use intck to find the difference:

``diff_minutes = intck('minute',onset_ts,rand_ts);``

Or do a simple calculation:

``diff_minutes = (rand_ts - onset_ts) / 60;``

Super User

## Re: Finding the "time since" in minutes for date and time

Create complete timestamps (datetime values) out of your variables first:

``onset_ts = dhms(onset_date,0,0,onset_time);``

Then you can use intck to find the difference:

``diff_minutes = intck('minute',onset_ts,rand_ts);``

Or do a simple calculation:

``diff_minutes = (rand_ts - onset_ts) / 60;``

Discussion stats