Posted by
Richard Ristow on
Dec 10, 2013; 11:31pm
URL: http://spssx-discussion.165.s1.nabble.com/How-to-calculate-time-difference-minutes-in-syntax-tp5723526p5723572.html
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