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!

How to deduct lunch time 1

Status
Not open for further replies.

projecttoday

Programmer
Feb 28, 2004
208
US
I have 3 fields, all defined as Date/Time fields:

startdateandtime
enddateandtime
lunchtime

I am trying to calculate the enddateandtime minus the startdateandtime minus the lunchtime.

This much works:

DateDiff("h",startdateandtime,enddateandtime)

But I also need to deduct the lunchtime. How do I do this?


Additional info:
A date and time are stored in startdateandtime and enddateandtime. Only a time is stored in lunchtime. I am using a format of short time for lunchtime and this seems to work for displaying a lunch time. This is a time such as 0:30 (30 minutes), 1:00 (an hour), etc.
 
What about this ?
Code:
Format(enddateandtime-startdateandtime-lunchtime,"h:mm")

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


FYI,

Date/Time values identify a POINT in time.

Start at this date/time.

End at this data/time.

Your lunch "time" is not a point in time, but rather a DURATION.

Time worked is a duration, calculated by [End Data/Time] - [Start Date/Time] and then subtracting the lunch duration.

[TimeWorked] = [End Data/Time] - [Start Date/Time] - [Lunch Duration]

Of course the DateDiff function can make that simpler (or not)

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
dHookum's solution appears to be working. I may try the others, maybe not. Thanks all.
 
dHookum's solution appears to be working
Even for lunch time of 30 minutes ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Actually I'm off today and I didn't test it very well before I left work last night and the database is on the computer at work. I'll test it tomorrow.
 
Sure enough, dHookum's first solution does not work for fractions of an hour. So I changed it to his second solution and that appears to be working.
 
Your initial statement used
Code:
DateDiff("h",startdateandtime,enddateandtime)
so I just left it as was thinking you were satisfied. Glad to hear you got this sorted out.

Duane
Hook'D on Access
MS Access MVP
 
Just to know, did you try mine ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top