|
-
Aug 15th, 2005, 11:22 AM
#1
Thread Starter
Hyperactive Member
Access Formula (DiffDate)
Hello,
I was wondering how I can make Microsoft Access calculate the difference between dates. Where a column contains the time the employee entered in and another column containing the time the employee left. I would like to have in a decimal form (for example: if somone cameat 8:30 and left at 10) the calculated field would contain 1.5). Any help would be really appreciated. Thanks in advance!
-
Aug 15th, 2005, 11:58 AM
#2
Re: Access Formula (DiffDate)
VB Code:
MsgBox (DateDiff("n", Text0.Value, Text2.Value) / 60)
Will accomplish what you want..I tried using hours..but it wouldnt give me a decimal number :/
-
Aug 15th, 2005, 02:28 PM
#3
Re: Access Formula (DiffDate)
This may work a little better for you:
VB Code:
Private Sub Command1_Click()
Dim intMinutes As Integer
Dim intHours As Integer
Text0 = "8:30"
Text3 = "10:00"
intHours = 0
intMinutes = DateDiff("n", [Text0], [Text3])
intHours = intMinutes \ 60
intMinutes = intMinutes - (intHours * 60)
Text5 = intHours & ":" & Format(intMinutes, "00")
End Sub
Regards,
Mark
Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."
-
Aug 15th, 2005, 02:46 PM
#4
Re: Access Formula (DiffDate)
I was reviewing you post again and I noticed that you wanted the result to be "1.5", so I adjusted my code to return both "1:30" and "1.50":
VB Code:
Private Sub Command1_Click()
Dim intMinutes As Integer
Dim intHours As Integer
Text0 = "8:30"
Text3 = "10:00"
intHours = 0
intMinutes = DateDiff("n", [Text0], [Text3])
intHours = intMinutes \ 60
intMinutes = intMinutes - (intHours * 60)
'The Following line will return '1:30'
Text5 = intHours & ":" & Format(intMinutes, "00")
'The Following line will return '1.50'
Text7 = intHours & "." & Format(100 / (60 / intMinutes), "00")
End Sub
Regards,
Mark
Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."
-
Aug 16th, 2005, 03:08 AM
#5
Re: Access Formula (DiffDate)
An alternative:
Code:
cdbl(cdate("10:00")-cdate("08:30"))*24
Where the Cdates are you can use a field with the time in.
Note: This will probably only work for time differences, or date/times on the same date. Different dates would produce weird results
Feeling like a fly on the inside of a closed window (Thunk!)
If I post a lot, it is because I am bored at work! ;D Or stuck...
* Anything I post can be only my opinion. Advice etc is up to you to persue...
-
Aug 16th, 2005, 08:04 AM
#6
Re: Access Formula (DiffDate)
 Originally Posted by Ecniv
An alternative:
Code:
cdbl(cdate("10:00")-cdate("08:30"))*24
Where the Cdates are you can use a field with the time in.
Note: This will probably only work for time differences, or date/times on the same date. Different dates would produce weird results 
Nice piece of code!!!
Regards,
Mark
Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|