Adding fields with a time format

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Does anyone know how to make access add a time field?
Example: In one field the time is 6:00 AM, and in another field the time is
2:00 PM. I want it to add the total hours between the 2 fields. hours in this
example being 8. Anyone know???
 
Sure, if it is a date/time field just use subtraction.

My question is, what format dod you use for that field? Is it a text field,
a number, a date? Normalized database design would call for a date/time
field if you will be doing math on the duration.

Rick B
 
Here is a function that I use to add "Append" the Period field to a table:
Hope this helps.

'*********************
Public Sub Add_Field()
'*********************
Dim db As Database
Dim tdf As TableDef
Dim fld As Field

Set db = CurrentDb
Set tdf = db.TableDefs!All_Deals_Source

Set fld = tdf.CreateField("Period")

fld.Type = dbInteger

tdf.Fields.Append fld

Set db = Nothing

End Sub
 
Does anyone know how to make access add a time field?
Example: In one field the time is 6:00 AM, and in another field the time is
2:00 PM. I want it to add the total hours between the 2 fields. hours in this
example being 8. Anyone know???

An Access Date/Time field will handle times from 00:00 to 23:59:59 but
not longer - it's actually stored as a Double Float count of days and
fractions of a day since midnight, December 30, 1899; if the times
were to add up to 25 hours, it would store #12/31/1899 01:00:00# and
display as one hour. There is no format allowing display of hours over
24. Therefore a date/time isn't really a good choice for durations!

I'd suggest that you store the duration in a Long Integer field, a
count of minutes. To display it as hours and minutes use an expression
like

[Duration] \ 60 & Format([Duration] MOD 60, ":00")

To fill the field using a form, you can use two unbound textboxes for
hours and minutes, and calculate the total minutes in each textbox's
AfterUpdate event.

John W. Vinson[MVP]
 
Back
Top