Adding Time Values

S

Stan

I have a time value of say 8:45 am and I want to add hours and minutes to it
such as 8:30 to arrive at and end time that is displayed in hh:nn am/pm. In
other words 7:00 am plus 9:00 would equal 4:00 pm.

Any thoughts?

Many thanks if you can help!
 
R

rowiga

Use the DateAdd function

DateAdd('h',[YourAddedHoursField -or- Constant],[YourDateFieldToAddTo])
 
J

John Vinson

I have a time value of say 8:45 am and I want to add hours and minutes to it
such as 8:30 to arrive at and end time that is displayed in hh:nn am/pm. In
other words 7:00 am plus 9:00 would equal 4:00 pm.

Date/Time values are designed to store points in time, and don't work
as well for durations. There is a DateAdd() function which will let
you add either minutes or hours to a date/time field to get a later
date/time value - e.g.

DateAdd("n", 540, #07:00#)

will come out 4pm. However, it doesn't (using that function) let you
add a date/time value to another date/time value.

IF you will never be adding more than 24 hours, though, you can just
"stretch" the rules a bit and simply use the + addition operator. A
date/time value is stored as a Double Float number, a count of days
and fractions of a day (times) since midnight, December 30, 1899; as
such, you could have #3/9/2005 07:15AM# stored in the table field
[StartTime], and #08:00# - which is actually stored as 0.33333333333
and corresponds to #12/31/1899 08:00:00# - in the ShiftLength field.
With that data, you could have

ShiftEnd: [StartTime] + [ShiftLength]

and get #3/9/2005 03:15PM# as a result.

If you're planning to store all three fields - shift start, shift end,
and shift length - in a table, you may want to reconsider; one of the
fields is redundant derived data (you pick which but any one can be
calculated from the other two).

John W. Vinson[MVP]
 
Top