Hour addition

Discussion in 'AutoCAD' started by Al, Jul 27, 2007.

  1. Al

    Al Guest

    We have a program that trends our current plant steam usage and uses VBA
    for applications. I'd like to use the do...loop and loop it until I reach
    a time 8 hours away.

    How do I add 8 hours to the currect time?

    Thanks
     
    Al, Jul 27, 2007
    #1
  2. Al

    fredg Guest

    I have no idea what you mean by using a do..loop for this purpose,
    but to add 8 hours to the current time, use:
    =DateAdd("h",8,Now())

    Fred
     
    fredg, Jul 27, 2007
    #2

  3. You don't need to loop to add eight hours to the current time, but you may
    need it if you want to do something for each of the eight hours, so here are
    examples with and without looping. See 'DateAdd Function' in the help files
    for more information.

    Public Sub EightHoursFromNow()

    Dim dtmNow As Date

    dtmNow = Now()
    Dim intLoop As Integer

    Debug.Print "No looping required: " & DateAdd("h", 8, dtmNow)
    Debug.Print "------------------------------------------------"
    Debug.Print "Starting loop"
    For intLoop = 0 To 8
    Debug.Print intLoop, DateAdd("h", intLoop, dtmNow)
    Next intLoop

    End Sub
     
    Brendan Reynolds, Jul 27, 2007
    #3
  4. Al,

    No need for a loop:
    dteMyTime = DateAdd("h", 8, dteMyTime)

    Regards,
    Graham R Seach
    Microsoft Access MVP
    Sydney, Australia
     
    Graham R Seach, Jul 27, 2007
    #4
  5. Al

    Al Guest

    Thanks to all who responded, You all were correct in that I had no need
    for the loop, It is work well, I just have to fine tune it now.
     
    Al, Aug 1, 2007
    #5
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.