2

I want to compute the sleep duration of my participants. As items I have the bed time and the time they got out of bed (some went to bed before 00:00 and some after). Format is hhmmss.

To compute the sleeping Time I already found this code:

DATA LIST FREE / outofbed bedtime (2TIME5).
BEGIN DATA
08:00 22:00
06:00 21:00
05:30 20:30
21:45 07:00
END DATA.

DO IF outofbed < bedtime.
  COMPUTE sleepDur = 24 - CTIME.HOURS(bedtime-outofbed).
ELSE.
  COMPUTE sleepDur = CTIME.HOURS(outofbed-bedtime).
END IF.
EXECUTE.

Problem is: Some went to bed at p.e. 00:45:00 and woke up at 09:30:00. The sleep time I got is 8:75 (instead of 8:45). What can I do differently to get the right answers?

(sorry, English is not my first language)

2
  • 1
    Welcome to Stack-Overflow! +1 for the good question with the reproducible example. The explanation is simple though - the variable you computed sleepDur is a numerical value which gives the answer as the number of hours. Note that the value you get is not 8:75 but 8.75 as in eight hours and three quarters... Commented May 14, 2024 at 19:27
  • 1
    Thanks for the answer. I was so tired yesterday hahah. Now in the morning it seems so obvious Commented May 15, 2024 at 7:37

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.