Results 1 to 7 of 7

Thread: how many hours late..

  1. #1
    New Member
    Join Date
    Sep 12
    Posts
    3

    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..

  2. #2
    Frenzied Member SamOscarBrown's Avatar
    Join Date
    Aug 12
    Location
    NC, USA
    Posts
    1,557

    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.

  3. #3
    Frenzied Member SamOscarBrown's Avatar
    Join Date
    Aug 12
    Location
    NC, USA
    Posts
    1,557

    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

  4. #4
    Fanatic Member
    Join Date
    Sep 12
    Location
    To the moon and then left
    Posts
    528

    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.
    For health reasons i try to avoid reading unformatted Code

  5. #5
    Frenzied Member SamOscarBrown's Avatar
    Join Date
    Aug 12
    Location
    NC, USA
    Posts
    1,557

    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)

  6. #6
    Fanatic Member
    Join Date
    Sep 12
    Location
    To the moon and then left
    Posts
    528

    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.
    For health reasons i try to avoid reading unformatted Code

  7. #7
    Frenzied Member SamOscarBrown's Avatar
    Join Date
    Aug 12
    Location
    NC, USA
    Posts
    1,557

    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
  •