Representing a time span in a database

J

James Minns

Hi all,
I have to represent a time span in my database; What would be the accepted
method for doing this?
If I use date/time, the user can't enter a value above 24 hours.

I have to enter and store numbers like 650:34:12 (hours minutes and seconds)

Ideas anyone?

Thanks, James
 
J

John Vinson

Hi all,
I have to represent a time span in my database; What would be the accepted
method for doing this?
If I use date/time, the user can't enter a value above 24 hours.

I have to enter and store numbers like 650:34:12 (hours minutes and seconds)

Ideas anyone?

Thanks, James

Durations are best stored in a number field, NOT in a Date/Time field
(which is best suited for recording exact moments in time). You could
store the duration in a Long Integer count of seconds (2342052 in this
case); you can use an expression like

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

to display in hh:nn:ss format; and you can use three unbound textboxes
on a Form with some VBA code to enter and display the value.

John W. Vinson[MVP]
 
K

Ken Snell \(MVP\)

Decide on how you want to actually store the value (in this case, probably
seconds is good), and store the value in a long integer field. You then can
convert the seconds back to hours:minutes:seconds via query calculation.

As for user entry, I suggest you use three textboxes: one for hours, one for
minutes, one for seconds. Then let the form's BeforeUpdate event calculate
the number of seconds and write that value to the seconds field.
 
J

James Minns

James Minns said:
Hi all,
I have to represent a time span in my database; What would be the accepted
method for doing this?
If I use date/time, the user can't enter a value above 24 hours.

I have to enter and store numbers like 650:34:12 (hours minutes and
seconds)

Thanks, John and Ken!
I'll store the number of seconds, and input the values from 3 textboxes!

James
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top