How to sum date/time field (1 Viewer)

jg_1981

New member
Local time
Today, 18:03
Joined
Oct 7, 2021
Messages
19
Hello everyone!

I have a problem to solve: how to sum a date/time field inm access?

I have a table with multiple fields, one of them it's the "Hour" field. When I apply the total option, I want to sum the total of hours in that fiel.

I want to obtain the 09:00 result.

1688037594523.png


But the accesss gives me the result below

1688037656228.png


How can I turn this around?

Thank you all for your help.

Best regards

JG

 

Galaxiom

Super Moderator
Staff member
Local time
Tomorrow, 03:03
Joined
Jan 20, 2009
Messages
12,852
You don't. DateTime fields are for recording moments in time, not amounts of time.

Record the number of seconds, minutes or hours is integers and sum them.
 

Ranman256

Well-known member
Local time
Today, 13:03
Joined
Apr 9, 2015
Messages
4,337
calculate the elapsed time in integer minutes (not time format). Then just sum the minutes.
 

jg_1981

New member
Local time
Today, 18:03
Joined
Oct 7, 2021
Messages
19
You don't. DateTime fields are for recording moments in time, not amounts of time.

Record the number of seconds, minutes or hours is integers and sum them.
Thanks for ypur reply! I'll try that! Not what I want but thanks anyways!
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 12:03
Joined
Feb 28, 2001
Messages
27,188
The real headache would occur when your total of several elapsed times exceeded one day, because that is almost impossible for novices to format correctly without a little help. But your expected total of 9:00 should have worked if you did this carefully.

Despite the suggestions to convert the times so that you can count minutes (which are actually not wrong), what you showed us in post #1 SHOULD have produced a total other than 0:00 because of the way date/time fields are stored. Which means something else is going on that is (to us) as yet unseen.

How did you compute the sum? If it was SQL, show us the SQL statement. If you created a query using the query design grid, open that query in SQL view, which is text you can cut/paste. If it wasn't SQL, then what did you do?

The behavior you showed would be correct if somehow an integer got involved, because DATE fields keep time as fractions of a day. If this supposed integer was somehow involved, it would strip the fractions. The other possibility is that those times are actually strings despite their appearance, and SUM doesn't work too well with string data types. At least, not as you might expect.
 

GPGeorge

Grover Park George
Local time
Today, 10:03
Joined
Nov 25, 2004
Messages
1,873
Hello everyone!

I have a problem to solve: how to sum a date/time field inm access?

I have a table with multiple fields, one of them it's the "Hour" field. When I apply the total option, I want to sum the total of hours in that fiel.

I want to obtain the 09:00 result.

View attachment 108591

But the accesss gives me the result below

View attachment 108592

How can I turn this around?

Thank you all for your help.

Best regards

JG

The secret is that your screenshots do not display times; they display elapsed periods of time. I.D., I.E., 1:30 would normally be the point in time either one hour and thirty minutes after midnight or one hour and thirty minutes after noon. The AM/PM is missing, so that's another level of ambiguity.

Instead, what you have displayed is supposed to represent an elapsed time. It represents a duration of 90 minutes. It is formatted to resemble a time.

That can take a bit of thought, sometimes, in order to understand why they are different.

The problem comes about because we can use our experience and human knowledge to interpret the representation differently when we see what we assume to be a point in time or a duration of time (the absence of an AM/PM is a partial clue). To Access, that kind of subtlety is a serious problem.

The solution is not to format anything for display until you get to the very end of the process when you are ready to show the user "1:30" as a specially formatted representation of "one and a half hours" or "9:00" as a specially formatted representation of "nine hours".
Others have offered ways to calculate the values you need.
 
Last edited:

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 12:03
Joined
Feb 28, 2001
Messages
27,188
To further clarify: IF (and only if) your data storage is to a DATE field but you NEVER involve an actual date, then for the first 23 hours, 59 minutes, and 59 seconds, you CAN add times in DATE fields because the times will represent times on day 0 of the Access calendar. The normal formatting routines will work for that long. The MOMENT you reach or exceed one day, you are done with that approach, because the Windows and Access date formatting routines do not support a format such as hhh:nn:ss - hours (greater than a day), minutes, and seconds. They only go up to 23:59:59 and then flip over to the start of the next day.

@GPGeorge, your explanation is absolutely correct, but in the case presented, up to one day of accumulated time, the two concepts APPEAR the same and even WORK the same. Which is why I originally chimed in that something else was going on. Even though all of the other replies that say "don't do it this way" are correct.
 

Users who are viewing this thread

Top Bottom