Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TimeIt Script

Status
Not open for further replies.

Keyster86

IS-IT--Management
Jul 23, 2008
50
US
Hello all!

I am trying to create a TimeIt function...however, I am running into one trouble area. I have the following script; however, when the clock reaches past Midnight, the timing goes all wrong - I can't for the life of me figure out what I am doing wrong here.

-----------------------------------------------------
Log file output:
-----------------------------------------------------
7/23/2008 23:50:21: IE Browser was started.
It has been 19.03 hours since script was started.
7/23/2008 23:50:21: Firefox Browser was started.
It has been 19.03 hours since script was started.
7/24/2008 00:05:22: IE Browser was started.
It has been -17007 seconds since script was started.
7/24/2008 00:05:22: Firefox Browser was started.
It has been -17007 seconds since script was started.

-----------------------------------------------------
TimeIt Script
-----------------------------------------------------

Function TimeIt(strTime)
Dim strTime1, strTime2

'Store current time
strTime1 = Time

'Find time difference in seconds from when script started
'to when this function is being called - then store in
'variable.
strTime2 = DateDiff("s",strTime,strTime1)

'Test for string value then LogIt based off the
'amount of time that has passed.
If strTime2 < 60 Then
'Round to two decimal places.
strTime2 = Round(strTime2,2)
'Log to file function
LogIt(" It has been " & strTime2 & " seconds since script was started.")
Else If strTime2 = 60 Or strTime2 > 60 And strTime2 < 3600 Then
strTime2 = strTime2/60
strTime2 = Round(strTime2,2)
LogIt(" It has been " & strTime2 & " minutes since script was started.")
Else If strTime2 = 3600 Or strTime2 > 3600 And strTime2 < 86400 Then
strTime2 = strTime2/3600
strTime2 = Round(strTime2,2)
LogIt(" It has been " & strTime2 & " hours since script was started.")
Else If strTime2 > 86400 Then
strTime2 = strTime2/86400
strTime2 = Round(strTime2,2)
LogIt(" It has been " & strTime2 & " days since script was started.")
End If
End If
End If
End If

'clean memory
Set strTime1 = Nothing
Set strTime2 = Nothing
End Function
 
Instead of using Time() use something that includes the date and time...i.e. Now()

Essentially your current script is probably evaluating something like this.


WScript.Echo DateDiff("s", #7:32:59 PM#, #7:31:59AM#)

as far as it's concerned the difference is a negative number.

using Now()....well try this out..we compare the current date and time with the date and time of the following day

WScript.Echo DateDiff("s", Now(), DateAdd("d", 1, Now()))

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top