Converting Date to WMI Date

by Jan 21, 2013

WMI (Windows Management Instrumentation, Get-WmiObject) uses a specific (DTMF) format for date and time. You can easily convert regular date and time information into this format:

PS> $date = Get-Date
PS> $wmidate = [System.Management.ManagementDateTimeConverter]::ToDmtfDateTime($date)
PS> $wmidate
20121231100600.751338+060
PS> $date = Get-Date
PS> $wmidate = [System.Management.ManagementDateTimeConverter]::ToDmtfDateTime($date)
PS> $wmidate
20121231100600.751338+060

Likewise, you can convert WMI date and time information back to a regular date and time object. This code tells you when your system was rebooted the last time:

PS> $os = Get-WmiObject -Class Win32_OperatingSystem
PS> $os.LastBootUpTime
20121230214154.411427+060
PS> [System.Management.ManagementDateTimeConverter]::ToDateTime($os.LastBootupTime)
Sunday, December 30, 2012 21:41:54

Twitter This Tip! ReTweet this Tip!