Results 1 to 11 of 11

Thread: [RESOLVED] calculate total minutes between time value

  1. #1

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    5,204

    Resolved [RESOLVED] calculate total minutes between time value

    i am trying to calculate between two time values with a single click
    i tried to do something but no luck
    Code:
    Private Sub Command1_Click()
        Dim TimeDiff As Long
        Dim StartDate As Date
        Dim EndDate As Date
        EndDate = Time
        TimeDiff = DateDiff("n", StartDate, EndDate)
        TimeIN.Value = StartDate
        TimeOut.Value = EndDate
        TxtTotalWorked.Text = TimeIN.Value + TimeOut.Value
    End Sub
    no idea what to do
    any help will be appreciated
    regards
    salsa31
    Last edited by salsa31; Aug 21st, 2014 at 03:34 PM.

  2. #2
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    Re: calculate total minutes between time value

    TimeDiff will have the number of minutes but in you code you hasn't initialized StartDate so that will have a default time of midnight.

  3. #3

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    5,204

    Re: calculate total minutes between time value

    TimeDiff will have the number of minutes but in you code you hasn't initialized StartDate so that will have a default time of midnight.
    hey Mark of course you know that this code dosnt work at all
    i used once datediff, i realy forget this calculation method
    i realy dont know what to do

  4. #4
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    Re: calculate total minutes between time value

    Of course it works. It gives you the time from midnight to the current time. If that isn't what you want then you have to adjust your variables accordingly.

    Code:
    Private Sub Command1_Click()
    Dim TimeDiff As Long
    Dim StartDate As Date
    Dim EndDate As Date
    
        EndDate = Time
        TimeDiff = DateDiff("n", StartDate, EndDate)
        
        MsgBox "The number of minutes between " & StartDate & " and " & EndDate & " is " & TimeDiff
    
    End Sub

  5. #5

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    5,204

    Re: calculate total minutes between time value

    i am trying to calculate between
    timein.value & timeout.value and display the results in [minutes]

    TxtTotalWorked.Text needs to show me the total in minutes between this [timein.value & timeout.value]

  6. #6
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    Re: calculate total minutes between time value

    So what are TimeIn.Value and TimeOut.Value. Are these coming from a control, a class.........I have no idea what TimeIn and TimeOut are.

  7. #7

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    5,204

    Re: calculate total minutes between time value

    it is a dtpicker that its format is dtptime
    e.x
    this is TimeIn.Value 21:00:00 this is TimeOut.Value 22:00:00

    i want TxtTotalWorked.Text to calculate between the two of them

    here the calculation is 60 minutes

  8. #8
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    Re: calculate total minutes between time value

    Code:
    Private Sub Command1_Click()
    Dim TimeDiff As Long
    
        TimeDiff = DateDiff("n", TimeIn.Value, TimeOut.Value)
        
        TxtTotalWorked = TimeDiff
    
    End Sub

  9. #9

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    5,204

    Re: calculate total minutes between time value

    exactly!!
    tnk you very much mark
    i appreciate your help

  10. #10
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: [RESOLVED] calculate total minutes between time value

    You could even shorten that more by removing the un needed variable from the mix
    Code:
    Private Sub Command1_Click()
        TxtTotalWorked = DateDiff("n", TimeIn.Value, TimeOut.Value)  
    End Sub

  11. #11

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    5,204

    Re: [RESOLVED] calculate total minutes between time value

    You could even shorten that more by removing the un needed variable from the mix
    tnk you sir

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