time-diff in minutes

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

time-diff in minutes

Moon Kid
btw: Yes I have read the universial-section. ;)

I want to calculate the difference in minutes between two times on
the clock (hours and minutes). The point is that it is the length of a
nightshift. So the start is 23:15 and end is 7:15. This are 480 minutes
difference.

I tried two things

COMPUTE v04 = CTIME.MINUTES(v04bis - v04von).

and

COMPUTE v04 = DATEDIFF(v04bis, v04von, "minutes").

The result is still -960,00.

I realize the logic behind it. SPSS tread the time times as values not
as time-points. There is now way to say what is start and what is end
time. If it would be possible it would be quite easy for SPSS to give
me the correct diff.

How can I solve?

=====================
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: time-diff in minutes

Moon Kid
On 2014-03-29 18:09 Moon Kid <[hidden email]> wrote:
> COMPUTE v04 = DATEDIFF(v04bis, v04von, "minutes").

Little bug (wrong order of fields) but doesn't solve the problem.

COMPUTE v04 = DATEDIFF(v04von, v04bis, "minutes").

=====================
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: time-diff in minutes

David Marso
Administrator
In reply to this post by Moon Kid
How is SPSS to know you have two DIFFERENT dates?
Need to put the date info in if you are going to get this to work.
Alternatively if result is negative add the appropriate amount of time to the result.

Moon Kid wrote
btw: Yes I have read the universial-section. ;)

I want to calculate the difference in minutes between two times on
the clock (hours and minutes). The point is that it is the length of a
nightshift. So the start is 23:15 and end is 7:15. This are 480 minutes
difference.

I tried two things

COMPUTE v04 = CTIME.MINUTES(v04bis - v04von).

and

COMPUTE v04 = DATEDIFF(v04bis, v04von, "minutes").

The result is still -960,00.

I realize the logic behind it. SPSS tread the time times as values not
as time-points. There is now way to say what is start and what is end
time. If it would be possible it would be quite easy for SPSS to give
me the correct diff.

How can I solve?

=====================
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
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: time-diff in minutes

Bruce Weaver
Administrator
In reply to this post by Moon Kid
As David's reply suggests, it looks like you might have TIME variables that do not include DATE information.  You need DATETIME variables, which are discussed in the Universals section of the FM.  I don't have SPSS on this machine, so cannot test an example.  But IIRC, you can simply add a DATE variable and a TIME variable to get a DATETIME variable, like this:

NUMERIC DateTimeVar(datetime).
COMPUTE DateTimeVar = DateVar + TimeVar.

Use two DateTime variables computed in that manner in place of your v04bis and v04von variables.

HTH.


Moon Kid wrote
On 2014-03-29 18:09 Moon Kid <[hidden email]> wrote:
> COMPUTE v04 = DATEDIFF(v04bis, v04von, "minutes").

Little bug (wrong order of fields) but doesn't solve the problem.

COMPUTE v04 = DATEDIFF(v04von, v04bis, "minutes").

=====================
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
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

PLEASE NOTE THE FOLLOWING: 
1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above.
2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/).
Reply | Threaded
Open this post in threaded view
|

Re: time-diff in minutes

Jon K Peck
Alternatively, if you know that the bis time is always the next day, just add one day to the time (86400 since dates and times are measured in seconds), before doing the calculation.  Bruce is right that you can add dates and times - assuming that these are true SPSS date/time variables, because the measure is the same.


Jon Peck (no "h") aka Kim
Senior Software Engineer, IBM
[hidden email]
phone: 720-342-5621




From:        Bruce Weaver <[hidden email]>
To:        [hidden email],
Date:        03/29/2014 02:31 PM
Subject:        Re: [SPSSX-L] time-diff in minutes
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




As David's reply suggests, it looks like you might have TIME variables that
do not include DATE information.  You need DATETIME variables, which are
discussed in the Universals section of the FM.  I don't have SPSS on this
machine, so cannot test an example.  But IIRC, you can simply add a DATE
variable and a TIME variable to get a DATETIME variable, like this:

NUMERIC DateTimeVar(datetime).
COMPUTE DateTimeVar = DateVar + TimeVar.

Use two DateTime variables computed in that manner in place of your v04bis
and v04von variables.

HTH.



Moon Kid wrote
> On 2014-03-29 18:09 Moon Kid &lt;

> moonkid@

> &gt; wrote:
>> COMPUTE v04 = DATEDIFF(v04bis, v04von, "minutes").
>
> Little bug (wrong order of fields) but doesn't solve the problem.
>
> COMPUTE v04 = DATEDIFF(v04von, v04bis, "minutes").
>
> =====================
> To manage your subscription to SPSSX-L, send a message to

> LISTSERV@.UGA

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





-----
--
Bruce Weaver
[hidden email]
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

NOTE: My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.

--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/time-diff-in-minutes-tp5725092p5725100.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
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: time-diff in minutes

Moon Kid
In reply to this post by Moon Kid
On 2014-03-29 18:09 Moon Kid <[hidden email]> wrote:
> I want to calculate the difference in minutes between two times on
> the clock (hours and minutes).

This is my solution.

COMPUTE v04bis = v04bis + 86400.
COMPUTE v0v = CTIME.MINUTES(v04bis - v04von).
COMPUTE v04bis = v04bis - 86400.
EXECUTE.
--
<http://dontbubble.us/>

=====================
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: time-diff in minutes

Bruce Weaver
Administrator
If that gives the correct result, why not just do this?

COMPUTE v0v = CTIME.MINUTES(v04bis + 86400 - v04von).
EXECUTE.



Moon Kid wrote
On 2014-03-29 18:09 Moon Kid <[hidden email]> wrote:
> I want to calculate the difference in minutes between two times on
> the clock (hours and minutes).

This is my solution.

COMPUTE v04bis = v04bis + 86400.
COMPUTE v0v = CTIME.MINUTES(v04bis - v04von).
COMPUTE v04bis = v04bis - 86400.
EXECUTE.
--
<http://dontbubble.us/>

=====================
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
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

PLEASE NOTE THE FOLLOWING: 
1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above.
2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/).
Reply | Threaded
Open this post in threaded view
|

Re: time-diff in minutes

Richard Ristow
At 07:29 AM 3/30/2014, Bruce Weaver wrote:

>If that gives the correct result, why not just do this?
>
>COMPUTE v0v = CTIME.MINUTES(v04bis + 86400 - v04von).

A couple of stylistic points.

. EXECUTE isn't necessary. I remark, because if those who are list
guri post unnecessary EXECUTEs, we'll never teach everybody else not to.

. My own taste is against using 'magic numbers' like 86,400. Yes, all
of us know that that's the number of seconds in a day AND that SPSS
time values are in seconds; but our code will be read and modified by
any number of people who don't have those at their finger ends. SPSS
makes it easy:

COMPUTE v0v = CTIME.MINUTES(v04bis + TIME.HMS(24) - v04von).

. Finally, this code will work if the interval measured *always*
crosses a midnight boundary. If it is always less than 24 hours, but
doesn't necessarily cross a midnight boundary, then

COMPUTE vov = v04bis - v04von.
IF      vov LT 0
         vov = vov + TIME.HMS(24).
COMPUTE vov = CTIME.MINUTES(vov).

=====================
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: time-diff in minutes

Moon Kid
On 2014-04-02 19:22 Richard Ristow <[hidden email]> wrote:
> A couple of stylistic points.

Thx, I really like clean and beautiful code.

> . EXECUTE isn't necessary. I remark, because if those who are list
> guri post unnecessary EXECUTEs, we'll never teach everybody else not
> to.

Can you specify that? In my understanding and observation COMPUTE has
no effect without an EXECUTE.

=====================
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: time-diff in minutes

Bruce Weaver
Administrator
I think it is useful to make a distinction between development of syntax and the finished product -- or production code, as David called it recently.  While you are developing your syntax, you may want to include some EXECUTE commands to see the results immediately, and check that things are working as expected.  (Alternatively, you might wish to use some other command that forces a data pass -- e.g., DESCRIPIVES, or CROSSTABS, etc.)  But in the final version of your syntax, MOST of those EXECUTE (or other) commands can be removed, thus eliminating unnecessary data passes.  There are a few cases in which one must include an EXECUTE, but I have to rush off to a meeting right now, so will leave it to someone else to remind us of what those conditions are.  Over to you, Richard, David, Art...

HTH.


Moon Kid wrote
On 2014-04-02 19:22 Richard Ristow <[hidden email]> wrote:
> A couple of stylistic points.

Thx, I really like clean and beautiful code.

> . EXECUTE isn't necessary. I remark, because if those who are list
> guri post unnecessary EXECUTEs, we'll never teach everybody else not
> to.

Can you specify that? In my understanding and observation COMPUTE has
no effect without an EXECUTE.

=====================
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
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

PLEASE NOTE THE FOLLOWING: 
1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above.
2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/).