Time Data

P

pedalling

I am trying to record time data related to the number of
hours,minutes and seconds it takes for various events.
Are there ways to format time data other then the Time of
Day?
 
J

John Vinson

I am trying to record time data related to the number of
hours,minutes and seconds it takes for various events.
Are there ways to format time data other then the Time of
Day?

The Access Date/Time datatype is really more appropriate for points in
time than for durations. It's stored internally as a double float
number, a count of days and fractions of a day since midnight,
December 30, 1899; a duration of 18 hours would be stored as 0.75 and
corresponds to #12/30/1899 06:00:00 pm# in Long Date format. You can
use custom formats to some extent to display values less than 24
hours; for instance a format of "hh:nn" will display hours and
minutes.

However, times over 24 hours wrap around to December 31, 1899 - 26
hours 20 minutes will display as 02:20.

It's really probably better to store the duration as a Long Integer
number of seconds, and format the result for display. Here's an
off-the-cuff little function to convert any number of seconds to
hours, minutes, and seconds in hh:nn:ss format:

Public Function DurationString(lngSec As Long) As String
DurationString = Format(lngSecond, ":00")
lngSecond = lngSecond \ 60 ' integer divide to minutes
DurationString = Format(lngSecond, ":00") & DurationString
lngSecond = lngSecond \ 60 ' now to hours
DurationString = CStr(lngSecond) & DurationString
End Function
 

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