Announcement

Collapse
No announcement yet.

Manipulating Time (VBS)

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Manipulating Time (VBS)

    I want to be able to manipulate time (don't we all?) but in a simple way...

    Basically get the time now in hh:mm:ss format. then add on a few minutes. I picked 3 minutes, 21 seconds as a starting point...

    However, me being simple I found that when the time was nearing the end of the minute/hour then it added over 60.

    Also it seems to be dropping the 0 which is a slight problem too...

    Any suggestions on how to do this?


    Code:
    strSeconds = Second(Now()) +21
    strMinutes = Minute(Now()) +3
    
    
    msgbox "It's today... " & FormatDateTime(Now(), vbShortDate) & VBNewLine & VBNeWLine & VBNewLine & VBNewLine & _
    "The Time now is exactly: " & FormatDateTime(Now()) & VBNewLine & _
    "From concentrating hard, you've managed to bend time and space and fast forwarded slightly to: " & Hour(Now()) & ":" & strMinutes & ":" & strSeconds

    I thought perhaps I could do something like

    Code:
    If strSeconds > 59 Then
            strSeconds = 59 & strMinutes + 1
        ElseIf strMinutes > 59 Then
            strMinutes = 59
        End If
    This is my signature.

  • #2
    Re: Manipulating Time (VBS)

    example1:
    Code:
    addSeconds = -3600
    addMinutes = +60
    addHours   = 0
    
    'calculating newTime:
    strNewTime = TimeValue(DateAdd("h",addHours,Time))
    strNewTime = TimeValue(DateAdd("n",addMinutes,strNewTime))
    strNewTime = TimeValue(DateAdd("s",addSeconds,strNewTime))
    
    Wscript.Echo  strNewTime

    \RemS

    This posting is provided "AS IS" with no warranties, and confers no rights.

    __________________

    ** Remember to give credit where credit's due **
    and leave Reputation Points for meaningful posts

    Comment


    • #3
      Re: Manipulating Time (VBS)

      Ah, that makes sense... there's something that'll do all that for me thanks
      This is my signature.

      Comment


      • #4
        Re: Manipulating Time (VBS)




        And this one?
        Code:
        ' http://www.w3schools.com/vbscript/vbscript_ref_functions.asp
        
        addSeconds = -3600
        addMinutes = +60
        addHours   = +24
        
        'calculating:
        strNewDate = Now()
        strNewDate = DateAdd("h",addHours,strNewDate)
        strNewDate = DateAdd("n",addMinutes,strNewDate)
        strNewDate = DateAdd("s",addSeconds,strNewDate)
        
        Wscript.Echo  "You've managed to bend time and space and fast forwarded slightly to: " _ 
                       & TimeValue(strNewDate) & vbNewLine & vbNewLine & "(Time difference = " _
                       & DateDiff("n",Date,DateValue(strNewDate)) & " minutes from Now)"
        \Rems

        This posting is provided "AS IS" with no warranties, and confers no rights.

        __________________

        ** Remember to give credit where credit's due **
        and leave Reputation Points for meaningful posts

        Comment

        Working...
        X