Computing time spent

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

Computing time spent

Sara House
Hey everyone -

This is probably easy to do but I seem to be stumped (it is Friday after all).  I have a variable of start time on a task and another variable that is finish time.  I want to compute how much time they spent on the task from these variables.  How would I do this?  I would prefer syntax but I'll take what I can get.

Sara House
[hidden email]

=====================
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
Reply | Threaded
Open this post in threaded view
|

Re: Computing time spent

ViAnn Beadle
Look at the datediff function to see if that'll work. Alternatively,
assuming that both are datetime variables you can subtract time2 from time1
which will give you time in seconds and then you can go from there to the
correct level of granularity through division.

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Sara House
Sent: Friday, February 15, 2008 1:42 PM
To: [hidden email]
Subject: Computing time spent

Hey everyone -

This is probably easy to do but I seem to be stumped (it is Friday after
all).  I have a variable of start time on a task and another variable that
is finish time.  I want to compute how much time they spent on the task from
these variables.  How would I do this?  I would prefer syntax but I'll take
what I can get.

Sara House
[hidden email]

=====================
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

=====================
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
Reply | Threaded
Open this post in threaded view
|

Re: Computing time spent

Marks, Jim
In reply to this post by Sara House
Sara:
COMPUTE timegap =End_time - start_time.

gives the difference in seconds. You can calculate up to larger
intervals-- 86,400 seconds per day for e.g.

Or you can use DATEDIFF to get standard date units.

COMPUTE timegap = DATEDIFF(end_time,start_time,"months").

the help file says valid date units are
Years
Quarters
Months
Weeks
Days
Hours
Minutes
Seconds

HTH
--jim

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Sara House
Sent: Friday, February 15, 2008 2:42 PM
To: [hidden email]
Subject: Computing time spent

Hey everyone -

This is probably easy to do but I seem to be stumped (it is Friday after
all).  I have a variable of start time on a task and another variable
that is finish time.  I want to compute how much time they spent on the
task from these variables.  How would I do this?  I would prefer syntax
but I'll take what I can get.

Sara House
[hidden email]

=====================
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

=====================
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
Reply | Threaded
Open this post in threaded view
|

Re: Computing time spent

Richard Ristow
In reply to this post by ViAnn Beadle
At 03:47 PM 2/15/2008, ViAnn Beadle wrote:

>Assuming that both are datetime variables you can subtract time2
>from time1 which will give you time in seconds and then you can go
>from there to the correct level of granularity through division.

Exactly. Though, instead of division, I think it gives more readable
code to use the CTIME functions:

CTIME.MINUTES(time2-time1), or CTIME.HOURS(time2.time1), or CTIME.DAYS

=====================
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