Results 1 to 8 of 8

Thread: DIFF in hours and minutes

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,580

    DIFF in hours and minutes

    i need to have a diff in hours and minutes from this two time and store result in var Hour_Diff .... how to?

    example diff time from 00.12 and 14.45

    note:
    return the result in HH.MM format

    tkx.

  2. #2
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,872

    Re: DIFF in hours and minutes

    This is what the DateDiff function is for.
    It can return the difference between two DateTime variables in years,days, seconds, etc (look it up in the Help)
    If you return the difference in seconds you can easily calculate the number of hours and minutes and display it like you want.

  3. #3
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,145

    Re: DIFF in hours and minutes

    An example using a textbox that includes a date/time:
    Code:
    Private Sub Command1_Click()
        MsgBox DateDiff("n", Date, CDate(Text1.Text))  'where 'n' represents minutes
    End Sub
    
    Private Sub Form_Load()
        Text1.Text = Format(Now, "yyyy/mm/dd hh:mm")
    End Sub

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,580

    Re: DIFF in hours and minutes

    Quote Originally Posted by SamOscarBrown View Post
    An example using a textbox that includes a date/time:
    Code:
    Private Sub Command1_Click()
        MsgBox DateDiff("n", Date, CDate(Text1.Text))  'where 'n' represents minutes
    End Sub
    
    Private Sub Form_Load()
        Text1.Text = Format(Now, "yyyy/mm/dd hh:mm")
    End Sub
    i not completlly understand, sorry.

    admit have

    dim t1 as date, t2 as date
    dim Hour_Diff as date

    t1=0.12
    t2=14.26

    i need in Hour_Diff the diff between t1 and t2 in the format 00.00
    var Hour_Diff

  5. #5
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,872

    Re: DIFF in hours and minutes

    Do some tests yourself that's the best way to learn.

    Look up the help for TimeSerial, DateSerial and DateDiff.
    Do some experiments and try to write your own code.

  6. #6
    Frenzied Member
    Join Date
    May 2006
    Location
    some place in the cloud
    Posts
    1,886
    JG


    ... If your problem is fixed don't forget to mark your threads as resolved using the Thread Tools menu ...

  7. #7

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,580

    Re: DIFF in hours and minutes

    w0W!!!! TKS.
    RESOLVED!

    But now if i wauld to use a ">" operator i need a particular set of variable, or i can use a simple expression:

    if t2>t1 the stop

    or?

  8. #8
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,872

    Re: DIFF in hours and minutes

    Try it, do it, test it! Learn!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width