473,386 Members | 1,741 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,386 software developers and data experts.

DateDiff in Query

I am running a query with the following SQL below:

SELECT TimeClockHistory.ClockInDate, TimeClockHistory.ClockOutDate,
TimeClockHistory.Employee, Sum(DateDiff("n",[ClockIn],[ClockOut]))/60
AS TimeElapsed
FROM TimeClockHistory
GROUP BY TimeClockHistory.ClockInDate, TimeClockHistory.ClockOutDate,
TimeClockHistory.Employee;

ClockInDate, ClockOutDate, ClockIn, & ClockOut are all Date/Time
format.

I am trying to calculate the hours per week an employee works. Right
now when it is run, it might say... 8.31125455654 hours worked.

Is there any way, within the query I can make it so it will format
08:12 hours worked... As far as time is goes, a decimal format will not
work.

Any help would be greatly appreciated!

Feb 23 '06 #1
3 1982
To get a custom format from 8.31125455654 you will have to write some
code. Here is a little bit to help you get started:

Dim i As Single, j As Single, str1 As String
i = 8.31125455654
'--separate out the decimal portion of the number
'--and get the minutes
j = (i - Int(i)) * 60
If Int(i) < 10 Then
str1 = "0" & Int(i)
Else
str1 = Int(i)
End If
If Int(j) < 10 Then
str1 = str1 & ":0" & Int(j)
Else
str1 = str1 & ":" & Int(j)
End If

This will yield "08:18". Then you can append "hours worked"

HTH

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Feb 23 '06 #2
Thank you!

Feb 24 '06 #3
Here is a function I wrote, that converts a number of seconds to a
time.

USAGE:
sec2dur(DateDiff("s",[starttime],IIf(IsNull([stoptime]),Now(),[stoptime])))
Just modify to remove the & format(secs,"00") to display hhh:mm without
seconds.

Public Function sec2dur(seconds As Long) As String
'converts a start and stop time to number of seconds. and
'then displays as hhh:mm:ss

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

Feb 24 '06 #4

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

Similar topics

1
by: intl04 | last post by:
I'm trying to set up a query that will include a new field ('Days until completion') whose value is derived from the DateDiff function. I think I have the syntax correct but am not sure. Days...
4
by: Paolo | last post by:
I am having some problem with a Year Function. I have form on which I have 4 field which indicate dates and an additional form which sums those dates: These are the fields: YEARS...
15
by: PMBragg | last post by:
Thank you in advance. I'm trying to pull all inventory items from December of the previous year back to 4 years for my accountant. I know this can be done, but I'm drawing a blank. I've tried; ...
1
by: PMBragg | last post by:
ORINGINAL Post >Thank you in advance. I'm trying to pull all inventory items from December >of the previous year back to 4 years for my accountant. I know this can be >done, but I'm drawing a...
5
by: mcbill20 | last post by:
Hello all. I have a really basic question that I hope someone has a better answer for. I apologize in advance-- I know this is probably a really basic question but I am used to Oracle rathern than...
6
by: kevinjwilson | last post by:
I am trying to get the date difference between two dates but I don't want the function to include weekends in the calculation. Does anyone have an idea on how to make this work?
1
by: Shawn Yates | last post by:
I have query which shows when employees clock in (long time) and clock out(long time). To find the total hours worked in hours and minutes I have another field on my query with the following: ...
9
by: StevoNZ | last post by:
Hi, I am a little stuck with a query I am trying to build. Attemting to calculate the delivery time for a material. I have managed to utilise the DateDiff function, but have some additional...
1
by: Sultan Ali Alhassni | last post by:
I was trying to use the datediff function in the Update query and I added the following on the upate to field : Datediff("d", , where Sentdate: is a date stored in a table called cycle_table ...
4
by: KA NMC | last post by:
I know this is very simple...but the syntax is really screwing me up...Basically what I want to do is have this query check for orders that have been open two hours and more and does not have a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.