Re: how many hours late..
This should answer your question.....use Datediff and use the hour difference parameter (h).
http://msdn.microsoft.com/en-us/libr...(v=vs.80).aspx
Here's an example.....modify so that you can enter the hour the book was taken out and returned;
Private Sub Command1_Click()
Dim TimeIn As Date, TimeOut As Date, TmpDate As Date
Dim nHrs As Integer, nMins As Integer
TimeIn = DTPicker1.Value
TimeOut = DTPicker2.Value
If TimeOut <= TimeIn Then
MsgBox "Invalid time"
Exit Sub
End If
nHrs = DateDiff("h", TimeIn, TimeOut)
TmpDate = DateAdd("h", nHrs, TimeIn)
If TmpDate > TimeOut Then
nMins = nMins - 1
TmpDate = DateAdd("h", -1, TmpDate)
End If
nMins = DateDiff("n", TmpDate, TimeOut)
MsgBox nHrs & " Hrs " & nMins & " Mins"
End Sub
Private Sub Form_Load()
DTPicker1.CustomFormat = "dd/MM/yyyy hh:mm"
DTPicker1.Format = dtpCustom
DTPicker1.Value = Now
DTPicker2.CustomFormat = "dd/MM/yyyy hh:mm"
DTPicker2.Format = dtpCustom
DTPicker2.Value = Now
End Sub
Re: how many hours late..
Here---I did a quick one for you using textboxes
add four textboxes to your form and one command button
(make sure you enter in textbox 3 the date/time in the following format: mm/dd/yyyy h:m:s AM/PM)
Code:
Option Explicit
Private Sub Command1_Click()
Dim datetimebookdue As Date
Dim DateTimeBookReturned As Date
Dim numHrsLate As Integer
datetimebookdue = CDate(Text2.Text)
DateTimeBookReturned = CDate(Text3.Text)
numHrsLate = DateDiff("h", datetimebookdue, DateTimeBookReturned)
Text4.Text = Str(numHrsLate)
End Sub
Private Sub Form_Load()
Text1.Text = "2/12/2012 1:30:00 PM" 'date book taken out
Text2.Text = Str(DateAdd("d", 10, CDate(Text1.Text))) 'date book due (10 days later)
Text3.Text = "2/26/2012 4:30:24 PM"
End Sub
Re: how many hours late..
Considering, that Most libraries have a "due back"-deadline, he could Set it UP something like this:
Date1: Book taken out
Date2: due back-deadline (calculated by his Code, e.g. 2 Weeks)
Date3: Date when Book was really back.
Re: how many hours late..
Zvoni...that's what i did in my example.....only I put a difference of 10 days vice 14. I know the code is harder to read without actually seeing the form, but yeah, I thought of that for him....(text1, text2, text3-out, due, in)
Re: how many hours late..
Sam, i'm having a stressful week right now, so i Must have missed that, since i'm on my iPad right now.
But no harm done. :wave:
Re: how many hours late..
:-)
I know.....wait until you get MY age....you'll miss seeing a WHOLE lot more than that!!!!