How to calculate time difference (minutes) in syntax?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

How to calculate time difference (minutes) in syntax?

rtdammann
The data comes as dd/mm/yyyy hh:mm in one column.
Opened_date = 7/2/2013 11:37
Closed_date = 7/8/2013 14:32

Compute days = CTIME.DAYS (Closed_Date - Opened_Date).  
Execute.

Compute time = CTIME.MINUTES (Closed_time - Opened_time).
execute.

Compute daily_minutes = days*160. (because its a 9 hour day)

Compute abs_time = abs(time).
Execute.

COMPUTE Total_Minutes=Daily_Minutes + Abs_Time.
EXECUTE.

Any help would be appreciated.

Thanks
Ross
Reply | Threaded
Open this post in threaded view
|

Re: How to calculate time difference (minutes) in syntax?

David Marso
Administrator
Is it a 5 day week?  Do holidays count?  Some things to think about.
You are on the right track mostly with CTIME but there will be a bit more logic which to consider.
eg opened time later than closed time.
See also DATEDIFF function .
This sort of question has definitely been addressed in the archives of this list so
I encourage you to search.

rtdammann wrote
The data comes as dd/mm/yyyy hh:mm in one column.
Opened_date = 7/2/2013 11:37
Closed_date = 7/8/2013 14:32

Compute days = CTIME.DAYS (Closed_Date - Opened_Date).  
Execute.

Compute time = CTIME.MINUTES (Closed_time - Opened_time).
execute.

Compute daily_minutes = days*160. (because its a 9 hour day)

Compute abs_time = abs(time).
Execute.

COMPUTE Total_Minutes=Daily_Minutes + Abs_Time.
EXECUTE.

Any help would be appreciated.

Thanks
Ross
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: How to calculate time difference (minutes) in syntax?

Richard Ristow
In reply to this post by rtdammann
At 11:34 AM 12/9/2013, rtdammann wrote:

>The data comes as dd/mm/yyyy hh:mm in one column.
>Opened_date = 7/2/2013 11:37
>Closed_date = 7/8/2013 14:32

First of all, get rid of all those Execute statements! They do
nothing for you, except to require the data to be re-read for each
one. 'Execute' is *not* necessary for a transformation command to take effect.

Now, I'm following David Marso's thinking: you want the total elapsed
time, counting 9 hours for each elapsed day (so, 540 minutes -- why do you have

>Compute daily_minutes = days*160. (because its a 9 hour day)

in your syntax?)

Assuming that the dates and times are in separate SPSS variables, I
think this will work:

COMPUTE Total_Minutes = 540 * CTIME.DAYS   (CloseDate - OpenDate)
                             + CTIME.MINUTES(CloseTime - OpenTime).
LIST.


List
|-----------------------------|---------------------------|
|Output Created               |10-DEC-2013 18:26:10       |
|-----------------------------|---------------------------|
   OpenDate OpenTime  CloseDate CloseTime Total_Minutes

07/02/2013   11:37  07/08/2013   14:32       3415.00

Number of cases read:  1    Number of cases listed:  1
=============================
APPENDIX: Test data, and code
=============================
DATA LIST LIST
     /OpenDate OpenTime CloseDate CloseTime
     (ADATE10, TIME5,   ADATE10,  TIME5).
BEGIN DATA
     7/2/2013 11:37     7/8/2013   14:32
END DATA.

COMPUTE Total_Minutes = 540 * CTIME.DAYS   (CloseDate - OpenDate)
                             + CTIME.MINUTES(CloseTime - OpenTime).
LIST.

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD