|
-
Oct 24th, 2012, 02:52 AM
#1
Thread Starter
New Member
how many hours late..
hai guys...i'm making a Library system and in returning transaction i would like to know how many hours late the borrower return the book..
i can get the time when the book was borrowed but the difference maybe of the time returned
i hope you understand my problem..
-
Oct 24th, 2012, 05:44 AM
#2
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
Last edited by SamOscarBrown; Oct 24th, 2012 at 06:13 AM.
-
Oct 24th, 2012, 07:52 AM
#3
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
-
Oct 24th, 2012, 10:17 AM
#4
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.
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
-
Oct 24th, 2012, 10:38 AM
#5
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)
-
Oct 24th, 2012, 10:50 AM
#6
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.
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
-
Oct 24th, 2012, 11:24 AM
#7
Re: how many hours late..
:-)
I know.....wait until you get MY age....you'll miss seeing a WHOLE lot more than that!!!!
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
|