How to Add Time values like LongTime "01:01:45" in Access 07 ?

R

RichMill

I have a field that stores longtime values. I would like to sum these in a
report column. Is there a function or way to do this?
 
G

Golfinray

I don't know that you can sum dates, but you could use datediff to convert
the dates to numbers and then sum the numbers.
Datediff("d",[firstdatefield],[seconddatefiled])
D will give you days, M months, etc
 
D

Dale Fye

I assume that you are using this time field to store duration data (amount of
time it took to do something). Generally I would advise you to store
something like seconds instead, because it is relatively easy to format that
as a duration, but adding time doesn't make a whole lot of sense (what is
12:00:00 + 13:00:00).

Do you mean you want to sum theses values in the footer of a report? You
could add a textbox to the footer of the report and do something like:

ControlSource:=Timevalue(Sum(TimeValue([yourFieldname]))), but if the sum of
your durations exceeds 24 hours, your results would only give you the
hours/min/sec, not the days. Or, you could create your own function that
would return a string that looks like " xx days hh:mm:ss". I would do this
something like:

ControlSource:= FormatDuration(Sum(TimeValue([yourField])))


Public function FormatDuration(SomeValue as date) as string

Dim strDays as string

If DateDiff("d", #12/30/1899#, SomeValue) > 0 then
strDays = DateDiff("d", #12/30/1899#, SomeValue) & " days "
else
strDays = ""
endif

FormatDuration =strDays & Format(SomeValue, "hh:nn:ss")

End function


--
HTH
Dale

Don''t forget to rate the post if it was helpful!

email address is invalid
Please reply to newsgroup only.
 

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