Working with Dates in WMI - The Datetime format
(Page 2 of 5 )
Again, the Datetime format is just a string representation. This statement includes a couple of points that you should keep in mind. First, dates and times in WMI are always treated as strings; and second, this is a formatted string—meaning that the string has several parts.
The string appears to be a fixed width floating point number. It actually has a set number of digit groups, each relating to a part of the date and time. It can be broken down into these parts very easily.
20080213195848.000000-300
Going back to the example date that we found in the beginning of this article, we can break this down into a legible date and time. The string you see actually represents February 13, 2008 7:58 PM EST. Here’s how.
- The first four digits represent a four digit year: 2008.
- The next two digits represent a two digit month: 02, or February.
- The next two digits represent a two digit day: 13, the 13th of the month.
- The next two digits represent a two digit hour in 24-hour format: 19, or 7 PM.
- The next two digits represent a two digit minute: 58.
- The final two digits before the decimal point represent a two digit second: 48.
- The first six digits following the decimal point represent microseconds. These are often not used, but must be represented by zeros to maintain the fixed length of the Datetime value.
- The last portion of the datetime format is a signed three digit value that represents the time zone as a GMT offset: -300, or minus 300 minutes (GMT -5 Hours). This represents Eastern Standard Time.
So the fixed width Datetime format looks like this: YYYYMMDDhhmmss.mmmmmm±UUU
It’s important to understand the last (UUU) portion of this thoroughly. By definition this is the offset in number of minutes that the time deviates from UTC. This is why it is recommended that dates are first converted to GMT, since GMT has a UTC offset value of 0.
Next: Converting VBScript dates to WMI Dates >>
More Windows Scripting Articles
More By Nilpo