Adding Times Together

G

Guest

Hello

i have a table which stores 2 string values; start_time (ie: 09:00:00) and
duration (ie: 01:45:00). How can I add them to get a result of 10:45:00? I
fugure it is using the dateadd function but I can't seem to get it to work
for me.

Thank you,

Daniel P
 
G

Guest

Nothing like answering your own question. i fiddled, ... and came up with
the following which seems to work

EndTime=Format(CDate(StartTime) + CDate(Duration), "hh:nn:ss")

If ever someone else needed to solve this problem.

Daniel P
 
J

John W. Vinson

Nothing like answering your own question. i fiddled, ... and came up with
the following which seems to work

EndTime=Format(CDate(StartTime) + CDate(Duration), "hh:nn:ss")

Well... that will work. Sort of, some of the time.

If the sum exceeds 24 hours it will return a result that's 24 hours off,
because Access stores date/time values as Double Float numbers, days and
fractions of a day since midnight, December 30, 1899. As a result, adding
"15:30" to "15:00" using your expression will give #12/31/1899 06:30:00# which
will display as 06:30.

I'd really, really suggest storing durations in a Number field - at the
granularity you need, e.g. Long Integer minutes if you don't care about
seconds, Long Integer seconds if you do - and using the DateAdd() function to
add the duration. Your text string can be converted to seconds with an
expression like

3600*Val(Left([Duration], 2)) + 60 * Val(Mid([Duration], 4, 2)) +
Val(Right([Duration], 2))


John W. Vinson [MVP]
 

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