-
Dec 15th, 2002, 09:54 AM
#1
Thread Starter
Hyperactive Member
date time help
I have a form that contains Date Opened Time Opened Date Closed and Time Closed.
The calculation for the diff in days between Date Opened and Date Closed works just fine including if the date is the same it returns 0 for days.
My problem is many times the Dates are O so I need to calculate the time diff so it can be saved to the DB.
For instance if Time Opened is 8:45:22 AM and Time Closed is 11:31:30 PM on the same day how do I calculate the hours? remembering that sometimes both the Open and Closed Times could be AM.
I know I need to start with an if Date Opened = Date Closed Then Time Diff = ??????
Thanks for any and all help. I'm hoping to get this solved by Monday since the boss is pressuring
-
Dec 15th, 2002, 11:07 AM
#2
Well ...
Try combining both date and time values into a single variable. A date variable in VB can accomodate both the date value and the time value. You could write something like this:
VB Code:
Dim MyDate1 As Date, MyDate2 As Date
MyDate1 = CDate(Format(DateOpened, "dd mmm yyyy") & " " & Format(TimeOpened, "hh:mm:ss"))
MyDate2 = CDate(Format(DateClosed, "dd mmm yyyy") & " " & Format(TimeClosed, "hh:mm:ss"))
MsgBox MyDate2 - MyDate1
You may tweak and tune this code, so don't use it in blind faith. Also whichever format string you use for the dates, use the same string in both the places.
.
-
Dec 15th, 2002, 11:15 AM
#3
Thread Starter
Hyperactive Member
Thanks for the quick rely honeybee. I will give it a try. Thanks again.
-
Dec 15th, 2002, 12:32 PM
#4
Thread Starter
Hyperactive Member
Well I have gotten this far
===============================
If OpenDate.Text = ClosedDate.Text Then
txtTATdays = 0
TimeDiff.Text = DateDiff("h", frmAdminInfo.txtTimeRecd.Text, txtTimeClosed.Text)
Else
============================
The problem now is the times in the text boxes are AM and PM so if the TimeRecd is something like 8:00 AM and the TimeClosed is 9:00PM I get only a one hour result. Of course if both times are in the AM or both in the PM it shows the difference properly.
Any suggestions ?
My BADD this does work sorry for my stupid mistake when testing it.
Thanks again
Last edited by Tailgun; Dec 15th, 2002 at 12:38 PM.
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
|