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!

Convert Date

Status
Not open for further replies.

TheLad

Technical User
Aug 3, 2001
3,846
GB
Guys

I downloaded a script to show System Uptime for a Windows device but the output is in minutes. Please can you offer any advice how I can convert the time into Days/Hours/Minutes. My efforts using DateDiff and/or DatePart have failed :(

The script is below:

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)
    msgbox dtmSystemUptime
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

Thanks

--------------------------------------
"Insert funny comment in here!"
--------------------------------------
 
let's say your system has been up 2985 minutes (two days, one hour, 45 minutes).
first you do:
hrs = int (orig_mins / 60) -----> give you 49
leftover_mins = orig_mins - (hrs * 60) ----> gives 45
days = int(hrs / 24) -----> gives 2
leftover_hr = hrs - (days * 24) -----> gives 1
whole_string = days & ":" & leftover_hrs & ":" & leftover_mins
the result would be: 2:1:45
cheers.
 
Another way:
Code:
...
  dtmSystemUptime = DateDiff("n", dtmLastBootUpTime, Now)
  intDays = dtmSystemUptime \ 1440
  intHours = dtmSystemUptime \ 60 - 24 * intDays
  intMinutes = dtmSystemUptime Mod 60
  MsgBox intDays & "d" & intHours & "h" & intMinutes & "m"
...

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Great stuff, thanks both for your replies.

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

Part and Inventory Search

Sponsor

Back
Top