Time is Text Field - Convert to hours and mins then calculate (1 Viewer)

gareth313

New member
Local time
Today, 04:21
Joined
Apr 12, 2018
Messages
1
Hi

I am working with a database and am querying some tables.

There is a "recorded labour hours" field that is a text field and has data such as:

1:30
4:30
0:30

I am wanting to take this data and have the ability to add them together so that the above results in 6:30.

Please help!!!

Regards

Gareth
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 06:21
Joined
Feb 28, 2001
Messages
27,140
OK, let me point out that Access doesn't do this quite right by itself. But it can help YOU to do it and maybe I can give you some ideas.

First, you need to consider a change of data format (at least temporarily). You didn't supply names, which is OK because I can make some up. In VBA code, you can compute what you want via DSum.

Code:
Dim TimeSum as Date
Dim AccumTime as String

...

TimeSum = DSum( "CDate([RecLabHrs])", "tblLabHrs", "...selection criteria" )
AccumTime = Format( TimeSum, "hh:nn" )

Note that this WILL NOT WORK if the sum is greater than 24 hours. For that you would need to build a function to do custom formatting. That is because Access does not have a time format that allows you to have something like 124:31:12 - an "elapsed" time format. It has limited date/time format conversions even though the math works out correctly. The math works because internally, Date format is a typecast of Double format and therefore can be used (carefully) for math operations on date. But for reasons I have yet to understand, they omitted one of the most common possible formats - elapsed time.

The SQL variant of this might resemble

DSum( "CDate([RecLabHrs])", "tblLabHrs", "...selection criteria" )
Code:
SELECT SUM(CDate([RecLabHrs])), EmpID FROM tblLabHrs WHERE LaborDate BETWEEN #<put start date here># AND #<put end date here># GROUP BY EmpID;

If you use the Search function on this forum you might find some articles on Date variables and Time Formatting. The SEARCH option is 3rd from the right on the thin ribbon near the top of this page, just under the box that shows your login name to the forum.
 

Users who are viewing this thread

Top Bottom