Hi:
Earlier in my career, I developed Time & Attendance software so I do have
definite opinions on this subject:
Above, Tom has given you a good, basic design. I definitely agree with
his comment about code to enforce the business rules. You really need
the added flexibility of client code such as VB, C, etc.
Allow me to add other fields you might find useful:
Time Card Table:
Time-Worked-ID INTEGER # Unique, Surrogate PKEY
Employee-ID INTEGER # FKey to employee
Project-ID INTEGER # Fkey to Project
StartTimestamp DATETIME
StopTimestamp DATETIME
timeworked Decimal
shift CHAR(1) # Fkey to shift table
paydate DATE
sys_adjust Decimal
New Field Discussion
1) shift: Typically, an employee starts working around the same time.
Entering a shift can default the StartTimestamp. Save data entry time.
2) timeworked: Generally, this is StartTime - StopTime. The database
purests will say you can compute it. True, but experience proved to me
that it was always nice to have this computed as soon as the StartTime
and StopTime were available.
Also, consider having data entry person enter the StartTime and the number of
hours worked, and have the system determine the StopTime. Generally, people hate
having to type in datetime strings.
3) paydate: For a first shift person working 8 to 5, the paydate is,
obviously, the date worked. But what about 3rd shift peope working 2300
to 0700. The start date is different from the end date. You may want
to compute a paydate different from the startdate.
4) sys_adjust: This is an adjustment is added/subtracted to the
timeworked for extraordinary occurrences such as working 2300 to 0700
during a daylight savings time change.
Epoch discussion
Tom's point about determining time from the EPOCH is valid. However, my
database of choice, Informix, has a datetime data type which allows
easy manipulation of the type. I simply subtract the StopTime from
the StartTime to get my interval. Obviously, it's not an ANSI standard,
but it sure simplifies this problem.
Good Luck with your project!
Ed