Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculating duration (time) - help with if statements 2

Status
Not open for further replies.

huv123

Technical User
Sep 10, 2005
79
AU
Hi - I was wondering if someone could help me

I need to calculate a person's sleep duration but since we ask about "usual" sleep times there is no date component

although in my case there are four possibilities

1. THey go to sleep before 12am and wakeup after 12am but before twelve pm (usually me!)
2. They go to sleep after 12am and wake up after 12am but before 12pm
3. They go to sleep after 12am and wakeup after 12pm the same day
4. They go to sleep after 12pm and wakeup before 12am the same day if they were a shift worker for example.

.
Could you help me with formulating the code for calculating this?
 
I thought it might be som ething like this?

If [SleepTime] <= [WakeTIme] Then

Me.Text2 = DateDiff("n", [SleepTime], [WakeTIme]) / 60 * 4

Else

Me.Text2 = DateDiff("n", [SleepTime], DateAdd("d", 1, [WakeTIme])) / 60 * 4

End If

End Sub
 




Hi,

"...there is no date component..."

WRONG!!!

Date and Time are related.

The VALUES are just NUMBERS.

The integer part of the number is the Date part and the fractional part is the Time part.

The UNITS of Date/Time is DAYS.

There IS a Date Component!

Skip,

[glasses]Did you hear what happened when the OO programmer lost his library?...
He's now living in OBJECT poverty![tongue]
 
Now that we have cleared that up...

When I meant there is no date companent I meant that I am not recording date anywhere. It would be farely straight forward if I was.
 


Are you not storing this data? I would think that DATE would be integral to the recordkeeping.

Skip,

[glasses]Did you hear what happened when the OO programmer lost his library?...
He's now living in OBJECT poverty![tongue]
 
What are the data types of SleepTime and WakeTIme ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 



Try something like this...
Code:
Dim dWake As Date

If [SleepTime] <= [WakeTime] Then
    dWake = [WakeTime]
Else
    dWake = [WakeTime] + 1
End If
MsgBox Abs([SleepTime] - dWake) * 24 & " HOURS"


Skip,

[glasses]Did you hear what happened when the OO programmer lost his library?...
He's now living in OBJECT poverty![tongue]
 
Hi Skip

No I am not storing the data regarding dates since we are discussing USUAL bedtime i.e. we are asking when do you USUALLY go to bed at night, where do you USUALLY get up and and how many hours do you USUALLY sleep at night.

I need to calculate sleep efficiency which is the amount of time spent asleep/time spent in bed (time getting out of bed -time going to sleep) X 100%.


I am usuing short date (i.e. 24 hours clock).

 
What about this ?
Me!Text2 = ([WakeTime]-([SleepTime]>[WakeTime])-[SleepTime])*24

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hi Skip. I think that works - I just made a few alterations so it reports it to a textbox value but it looks good. I will test it a little more and get back to you.

Thanks Chip and PHV - I will try both and see what happens.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top