calculating and adding time

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • madbrit
    New Member
    • Jul 2007
    • 5

    calculating and adding time

    I am designing a wages calculator based on time started, and time finished., the total time will be about 3-400 hours a month.

    how can I add time together to be over 24 hours,

    Saple code below ( i am a novis) this is written just to test the results.

    Thanks

    Private Sub Command1_Click( )
    Dim Time2 As Date
    Dim DiffInMins As Long
    Dim Cap1 As String
    Dim Cap2 As String
    Dim Cap12 As String
    Dim Cap13 As Double
    Dim cap14 As VbDateTimeForma t
    Dim DiffInHrsAndMin s As String
    Const MinutesPerDay As Long = 1440

    Cap1 = ("12:00")
    Cap2 = ("14:56")

    Time1 = CDate(Cap1)
    Time2 = CDate(Cap2)
    DiffInMins = DateDiff("n", Time1, Time2)

    DiffInHrsAndMin s = Format$(DiffInM ins / MinutesPerDay, "hh:nn")
    Cap12 = DiffInHrsAndMin s

    Cap13 = Val(Cap12)

    cap14 = Cap13

    Text3.Text = Cap12 ###get 02.56 as a result

    Text4.Text = Cap13 ### get 2 as a result

    cap14 = Cap13

    MsgBox (Cap13 * 2) ### get 4 as result

    MsgBox (cap14) ### get 2 as result




    End Sub
  • SkinHead
    New Member
    • Jun 2007
    • 39

    #2
    Variables Of Type Date In VB (DateTime In SQL Server) Are Actually 64 Bit Integers Of A Specific Format. These Numbers Can Obviously Be Displayed In Numerous Formats :

    01 Jan 2001 12:00
    12:00:Dec 31 2001
    etc

    However, While The DateDiff Function Returns The Number Of Intervals Between Two Dates, ie Also An Integer, You Will Not Be Able To Display It As A True Date/Time Variable.

    Specifically, If You Want The Result (Or Summation Of A Number) Of DateDiff Function(s) To Be In HH:NN Format, Then It's Up To You

    Eg

    nMinutes = DateDiff ('n', dtOne, dtTwo)

    szDiff = Format ( nMinutes DIV 60, "HH" ) & ":" & Format (nMinutes MOD 60, "NN")

    Comment

    • madbrit
      New Member
      • Jul 2007
      • 5

      #3
      sorry that does not help, how do i add time together,

      Thanks

      MaD

      Comment

      • madbrit
        New Member
        • Jul 2007
        • 5

        #4
        Not interested in the date aspect, just time

        Ta

        Comment

        • SkinHead
          New Member
          • Jun 2007
          • 39

          #5
          You Don't Add Time, As Such. You Just Add Minutes !

          This Running Total Can Be Displayed As HH:NN As I Suggested.

          Comment

          • madbrit
            New Member
            • Jul 2007
            • 5

            #6
            Thanks. I understand now.

            I have found the original .exe file from a year ago when i did this before, how can I convert this to be editable in VB, the computer crashed and source code not saved.

            Thanks

            MaD

            Comment

            • Killer42
              Recognized Expert Expert
              • Oct 2006
              • 8429

              #7
              This has been covered before. GTry a quick search on "VB decompiler".

              Comment

              Working...