Datetime.vbs

' Syntax:
'  CSCRIPT datetime.vbs
 
'Returns: Year, Month, Day, Hour, Minute, Seconds, Offset from GMT, Daylight Savings=True/False

strComputer = "."

' Date and time

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")

For Each objItem in colItems
    dtmLocalTime = objItem.LocalDateTime
    dtmMonth = Mid(dtmLocalTime, 5, 2)
    dtmDay = Mid(dtmLocalTime, 7, 2)
    dtmYear = Left(dtmLocalTime, 4)
    dtmHour = Mid(dtmLocalTime, 9, 2)
    dtmMinutes = Mid(dtmLocalTime, 11, 2)
    dtmSeconds = Mid(dtmLocalTime, 13, 2)
Next

' Daylight savings

Set Win32Computer = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem") 

For Each objItem In Win32Computer
   oGMT = (objItem.CurrentTimeZone / 60) 
   DaySave = objItem.DaylightInEffect 
Next

Wscript.Echo dtmYear & " " & dtmMonth & " " & dtmDay & " " & dtmHour & " " & dtmMinutes & " " & dtmSeconds & " " & oGMT & " " & DaySave

Calls:
Win32_OperatingSystem
Win32_ComputerSystem

Alternatives: Win32_LocalTime also gives the time

Related

GetDate.vbs - Return the current Year/month/Day and time
GetDate.cmd - Get todays date Windows batch file
Easter.vbs - Function to calculate the date of Easter

“If I had to live my life again, I'd make the same mistakes, only sooner” ~ Tallulah Bankhead.


© Copyright SS64.com 1999-2013
Some rights reserved