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!

Reporting Days wrong 1

Status
Not open for further replies.

TheLad

Technical User
Aug 3, 2001
3,846
GB
Guys

The script below reports the System Uptime. I found parts of this script on the web and with the help of a previous post here, I amended the output to report in days, hours and minutes. Unfortunately, the script appears not to report correctly at certain times of the month (mainly the beginning) and I cannot figure out why? eg. It is reporting my laptop has been up for 118 days when it should report it as 0 days (hours and minutes are correct)

The script is below, please can you offer any advice?

Code:
strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
    ("Select * from Win32_OperatingSystem")
 
For Each objOS in colOperatingSystems
    dtmBootup = objOS.LastBootUpTime
    dtmLastBootupTime = WMIDateStringToDate(dtmBootup)
    dtmSystemUptime = DateDiff("n", dtmLastBootUpTime, Now)
    intDays = dtmSystemUptime \ 1440
    intHours = dtmSystemUptime \ 60 - 24 * intDays
    intMinutes = dtmSystemUptime Mod 60
    msgbox "Device has been up for " & intDays & " days, " & intHours & " hours and " & intMinutes & " minutes"



Next
 
Function WMIDateStringToDate(dtmBootup)
    WMIDateStringToDate = CDate(Mid(dtmBootup, 5, 2) & "/" & _
        Mid(dtmBootup, 7, 2) & "/" & Left(dtmBootup, 4) _
            & " " & Mid (dtmBootup, 9, 2) & ":" & _
                Mid(dtmBootup, 11, 2) & ":" & Mid(dtmBootup,13, 2))
End Function

--------------------------------------
"Insert funny comment in here!"
--------------------------------------
 
[tt]Function WMIDateStringToDate(dtmBootup)
dim d,ts
d=dateserial(cint(Mid(dtmBootup, 1, 4)), cint(Mid(dtmBootup, 5, 2)), cint(Mid(dtmBootup, 7, 2)))
'time in second
ts=cint(Mid(dtmBootup, 9, 2))*60*60 + cint(Mid(dtmBootup, 11, 2))*60 + cint(Mid(dtmBootup,13, 2))
WMIDateStringToDate=DateAdd("s",ts,d)
End Function
[/tt]
 
tsuji:
ts=[!]CLng[/!](Mid(dtmBootup, 9, 2))*60*60 + cint(Mid(dtmBootup, 11, 2))*60 + cint(Mid(dtmBootup,13, 2))
 
Does it make a difference? I would be happy anything that works, so it is fine for me as well with clng().
 
tsuji, a day has 86400 seconds and this number can't be hold by an integer but a long.
 
I agree, but that number is ranging 0-23 before multiplying 60*60 and that's why cint() seems fine for me as well.
 
Thanks for your help...

--------------------------------------
"Insert funny comment in here!"
--------------------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top