473,397 Members | 2,116 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Time over 24 hours

I have designed a "Time Tracker Database"... Basically a Time Clock. I
have report that calculates the number of regular hours worked per
week.

Currently I am running the following query:

----------------------------------------------------------------------
SELECT DateFilter.Employee, DateFilter.TimeTypeIn,
Sum([ClockOut]-[ClockIn]) AS Expr1
FROM DateFilter
GROUP BY DateFilter.Employee, DateFilter.TimeTypeIn
HAVING (((DateFilter.TimeTypeIn)="Regular"));
ClockIn & ClockOut are both Time/Date
----------------------------------------------------------------------

Everything calculates correctly up to 24 hours. After that, it messes
up. I would like the sum to say something like 38:25:02

Any suggestions would be appreciated!

Feb 24 '06 #1
10 3341
Do the calculation in the smallest units you want to report. For example, if
you want hours and minutes, do the calculation in minutes. Format it later
the way you want it after you get the total. Instead of subtracting ClockIn
from ClockOut, use the DateDiff function and tell it to return minutes (n).
In your example, it appears you're wanting to track to the second, is that
correct?

Example:
TotalTime:Sum(DateDiff("s", [ClockIn], [ClockOut])) \ 3600 &
Format((Sum(DateDiff("s", [ClockIn], [ClockOut])) Mod 3600) / 86400,
":nn:ss")

Example from the Immediate window:
?10000 \ 3600 & Format((10000 Mod 3600) / 86400, ":nn:ss")
2:46:40

The problem you're running into is that you want elapsed time. An elapsed
time isn't a "time" data type, it is simply a number. For example, the
difference between 2pm and 3pm is 1 hour, not 1 o'clock (1:00). You are then
wanting it formatted as if it was a time.

--
Wayne Morgan
MS Access MVP
"Drum2001" <dr******@gmail.com> wrote in message
news:11**********************@v46g2000cwv.googlegr oups.com...
I have designed a "Time Tracker Database"... Basically a Time Clock. I
have report that calculates the number of regular hours worked per
week.

Currently I am running the following query:

----------------------------------------------------------------------
SELECT DateFilter.Employee, DateFilter.TimeTypeIn,
Sum([ClockOut]-[ClockIn]) AS Expr1
FROM DateFilter
GROUP BY DateFilter.Employee, DateFilter.TimeTypeIn
HAVING (((DateFilter.TimeTypeIn)="Regular"));
ClockIn & ClockOut are both Time/Date
----------------------------------------------------------------------

Everything calculates correctly up to 24 hours. After that, it messes
up. I would like the sum to say something like 38:25:02

Any suggestions would be appreciated!

Feb 24 '06 #2
That works great!! thank you!

Now here is a little twist... How would I make it so anything over 40
hours would be overtime?

Basically how would I code: TotalTime - 40:00:00 = (overtime)

Feb 24 '06 #3
"Drum2001" <dr******@gmail.com> wrote in
news:11*********************@u72g2000cwu.googlegro ups.com:
That works great!! thank you!

Now here is a little twist... How would I make it so anything
over 40 hours would be overtime?

Basically how would I code: TotalTime - 40:00:00 =
(overtime)

since the total time in seconds is sum(datediff("ss",[clockin],
[clockout]) as given by wayne,
Overtime in seconds is
IIF(sum(datediff("s",[clockin],[clockout])-40*60*60) >0, sum
(datediff("s",[clockin],[clockout])-40*60*60,0))

and that has to be reformatted as Wayne showed, .

Overtime =
IIF(sum(datediff("s",[clockin],[clockout])-40*60*60 >0, sum
(datediff("s",[clockin],[clockout])-40*60*60,0)/3600 &
Format((IIF(sum(datediff("s",[clockin],[clockout])-40*60*60 >0,
sum(datediff("s",[clockin],[clockout])-40*60*60,0) Mod 3600) /
86400, ":nn:ss")

which has to go into the query as a single line, is quite a
mess, and I'm sure I'm missing some () so use the User defined
function below.

overtime = SecToDur(IIF(sum(datediff("s",[clockin],[clockout])-
40*60*60 >0, sum(datediff("s",[clockin],[clockout])-40*60*60,0))

Public Function sec2dur(seconds As Long) As String
On Error Resume Next

Dim hrs As Long
Dim mins As Integer
Dim secs As Integer

hrs = Int(seconds / 3600)
mins = Int((seconds - (3600 * hrs)) / 60)
secs = seconds - (hrs * 3600 + mins * 60)

sec2dur = Format(hrs, "#,##0") _
& ":" & Format(mins, "00") & ":" _
& Format(secs, "00")

End Function

--
Bob Quintal

PA is y I've altered my email address.
Feb 25 '06 #4
What do I put where? If I put:

overtime = SecToDur(IIF(sum(datediff("s",[clockin],[clockout])-
40*60*60 >0, sum(datediff("s",[clockin],[clockout])-40*60*60,0))

In the query, it says "The Expression you entered has a function
containing the wrong number of arguments."

Feb 27 '06 #5
"Drum2001" <dr******@gmail.com> wrote in
news:11**********************@i39g2000cwa.googlegr oups.com:
What do I put where? If I put:

overtime = SecToDur(IIF(sum(datediff("s",[clockin], [clockout])- 40*60*60 >0, sum(datediff("s",[clockin],[clockout])-40*60* 60,0))
In the query, it says "The Expression you entered has a function containing the wrong number of arguments."

I parsed out your code, you are missing a parenthesis somewhere.
overtime =
SecToDur(
IIF(
sum(
datediff(
"s",[clockin],[clockout]
)
- 40*60*60 >0,
sum(
datediff(
"s",[clockin],[clockout]
)-40*60*60,0
)
)


1) in a query, you need a colon to define the column, instead of
an equals,
2) the nesting of parentheses can be a royal PITA. I oftem build
in notepad, tabbing in for each ( and out per ), to make sure
they're in the right places.

Overtime:
sectodur(
IIF(
sum(
datediff(
"s",[clockin],[clockout]
)
)-40*60*60 >0
,
sum(
datediff(
"s",[clockin],[clockout]
)
)-40*60-60
,
0
)

)

With this level of nested calls, I'd probably move the code to a
function.
--
Bob Quintal

PA is y I've altered my email address.
Feb 27 '06 #6
Thank you for your help again!

It looks like were closer. It seems as if it is subtracting 41 mins,
not 40 hours. Any suggestions?

With sample times entered, the queries come up with the following
results...
T
he Total Regular time = 51:59:31
The Total Overtime = 51:18:31

Feb 28 '06 #7
"Drum2001" <dr******@gmail.com> wrote in
news:11**********************@p10g2000cwp.googlegr oups.com:
Thank you for your help again!

It looks like were closer. It seems as if it is subtracting
41 mins, not 40 hours. Any suggestions?

With sample times entered, the queries come up with the
following results...
T
he Total Regular time = 51:59:31
The Total Overtime = 51:18:31

found this in the code I posted: )-40*60-60
which would give the exact 41 minutes instead of 40 hours error
you mentioned. It follows the second datediff. )-40*60*60 will
give the correct result. So sorry I can't type.

My employer keeps me on staff for my mental acuity, not my
physical dexterity.
--
Bob Quintal

PA is y I've altered my email address.
Feb 28 '06 #8
Bob,

Thank you very much for all your assistance!

That did work!


Bob Quintal wrote:
"Drum2001" <dr******@gmail.com> wrote in
news:11**********************@p10g2000cwp.googlegr oups.com:
Thank you for your help again!

It looks like were closer. It seems as if it is subtracting
41 mins, not 40 hours. Any suggestions?

With sample times entered, the queries come up with the
following results...
T
he Total Regular time = 51:59:31
The Total Overtime = 51:18:31

found this in the code I posted: )-40*60-60
which would give the exact 41 minutes instead of 40 hours error
you mentioned. It follows the second datediff. )-40*60*60 will
give the correct result. So sorry I can't type.

My employer keeps me on staff for my mental acuity, not my
physical dexterity.
--
Bob Quintal

PA is y I've altered my email address.


Mar 1 '06 #9
Is there anyway to make it like the following. If there is overtime,
then have Regular Time display = 80:00:00

If under 80:00:00, then display the correct hours

Drum2001 wrote:
Bob,

Thank you very much for all your assistance!

That did work!


Bob Quintal wrote:
"Drum2001" <dr******@gmail.com> wrote in
news:11**********************@p10g2000cwp.googlegr oups.com:
Thank you for your help again!

It looks like were closer. It seems as if it is subtracting
41 mins, not 40 hours. Any suggestions?

With sample times entered, the queries come up with the
following results...
T
he Total Regular time = 51:59:31
The Total Overtime = 51:18:31

found this in the code I posted: )-40*60-60
which would give the exact 41 minutes instead of 40 hours error
you mentioned. It follows the second datediff. )-40*60*60 will
give the correct result. So sorry I can't type.

My employer keeps me on staff for my mental acuity, not my
physical dexterity.
--
Bob Quintal

PA is y I've altered my email address.


Mar 20 '06 #10
"Drum2001" <dr******@gmail.com> wrote in
news:11*********************@t31g2000cwb.googlegro ups.com:
Is there anyway to make it like the following. If there is
overtime, then have Regular Time display = 80:00:00

If under 80:00:00, then display the correct hours

I could not get the original messages back via my ISP Google.
Anyway, It's just a matter of building up the calculations and
nesting them in IIF statements.

so if you have TotalTime (in seconds)
RegularTime is
iif(TotalTime > 80*60*60,80*60*60,Totaltime).

OverTime is
iif(TotalTime > 80*60*60,totaltime-80*60*60,0).

Those would go inside the SecToDur() function that I originally
provided in 2004

Public Function sec2dur(seconds As Long) As String
On Error Resume Next
Dim hrs As Long
Dim mins As Integer
Dim secs As Integer
hrs = Int(seconds / 3600)
mins = Int((seconds - (3600 * hrs)) / 60)
secs = seconds - (hrs * 3600 + mins * 60)
sec2dur = Format(hrs, "#,##0") & ":" & Format(mins, "00") & ":"
&
Format(secs, "00")
End Function

Drum2001 wrote:
Bob,

Thank you very much for all your assistance!

That did work!


Bob Quintal wrote:
> "Drum2001" <dr******@gmail.com> wrote in
> news:11**********************@p10g2000cwp.googlegr oups.com:
>
> > Thank you for your help again!
> >
> > It looks like were closer. It seems as if it is
> > subtracting 41 mins, not 40 hours. Any suggestions?
> >
> > With sample times entered, the queries come up with the
> > following results...
> > T
> > he Total Regular time = 51:59:31
> > The Total Overtime = 51:18:31
> >
> found this in the code I posted: )-40*60-60
> which would give the exact 41 minutes instead of 40 hours
> error you mentioned. It follows the second datediff.
> )-40*60*60 will give the correct result. So sorry I can't
> type.
>
> My employer keeps me on staff for my mental acuity, not my
> physical dexterity.
>
>
> --
> Bob Quintal
>
> PA is y I've altered my email address.



--
Bob Quintal

PA is y I've altered my email address.
Mar 21 '06 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Kenneth | last post by:
Hello, I'm having some serious problems debugging a script that I'm trying to make work. I'm working on a form where a user can type in a time (in the format of HH:MM), and another script...
4
by: flupke | last post by:
Is there an easy to convert following hour notation hh:mm to decimals? For instance 2 hours and 30 minutes as 2:30 to 2,50 I don't really know where to search for this kind of conversion. ...
5
by: Alan Webb | last post by:
Guys, I get this: Regular Hours are any hours less than the number of hours that can be worked before the hours begin to be counted as overtime in the period. Overtime Hours are any hours...
2
by: smatthews | last post by:
Access 2000 question Hi any help or advise required if possible i am trying to create a formula for a field. here is what i have currently rem:...
22
by: Drum2001 | last post by:
I have a table that tracks employee times. I have a column (Date/Time). Users, through a form, enter how long it takes them to complete a task. For example, 03:45 = 3 hours and 45 mins. I am...
7
by: nono909 | last post by:
I wrote the following time class for the following assignment.i need help in completing this program pleasee. Write a class to hold time. Time is the hour, minute and seconds. Write a constructor...
1
by: ken | last post by:
Mostly so I can find this again when I need it: function formatTime(t) { var myTime = t.value; var badFormat = "Bad format"; // Ensure we have a value if (myTime == "") { return(true); }
6
by: JamesG | last post by:
I'm trying to convert a unix timestamp to a readable time, such as 4 hours ago, or 25 minutes ago. My code is below: function ago($ts) { /* time difference */ $ts = (time() - $ts); if($ts <...
0
yasirmturk
by: yasirmturk | last post by:
Standard Date and Time Functions The essential date and time functions that every SQL Server database should have to ensure that you can easily manipulate dates and times without the need for any...
3
by: RN1 | last post by:
A Form has 2 TextBoxes where in users enter date & time. Example (in mm/dd/yyyy format): 09/20/2008 17:54 (1st TextBox) 09/29/2008 6:13 (2nd TextBox) How do I find out how much time (in...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.