Windows Scripting
  Home arrow Windows Scripting arrow Working with Dates in WMI
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
WINDOWS SCRIPTING

Working with Dates in WMI
By: Nilpo
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2009-02-09

    Table of Contents:
  • Working with Dates in WMI
  • The Datetime format
  • Converting VBScript dates to WMI Dates
  • Converting WMI dates to VBScript Dates
  • Building Queries with Dates

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Working with Dates in WMI


    (Page 1 of 5 )

    As you begin scripting with WMI, you will quickly learn that WMI uses its own date and time format. In order to build queries in WMI you will need an understanding of this date and time format as well as a knowledge of how to convert between WMI dates and traditional VBScript dates.

    WMI uses the CMI_Datetime format, commonly referred to as simply datetime.  On the surface, the datetime format is a string representation of a given date and time.  Like the VBScript’s VT_Date format, this is local to the current system.  Let’s take a look at an example.

    strComputer = "."

     

    Set objWMIService = GetObject("winmgmts:" & strComputer & "rootcimv2")

     

    Set colOperatingSystems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")

     

    For Each objOperatingSystem In colOperatingSystems

        Wscript.Echo objOperatingSystem.InstallDate

    Next

    This simple WMI script returns the date that the current operating was installed.

    20080213195848.000000-300

    At first glance, this script’s output is a bit ambiguous.  In fact, it looks almost cryptic.  But deciphering the datetime format is really not as hard as it might seem.

    More Windows Scripting Articles
    More By Nilpo


     

    WINDOWS SCRIPTING ARTICLES

    - More Windows Scripting Workarounds from Nilpo
    - Overloading Methods and More in VBScript
    - Improving MFC for Windows Vista
    - Regular Expressions in VBScript
    - Working with Dates in WMI
    - Completing Calendars with VBScript Date Func...
    - Building Calendars with VBScript Date Functi...
    - Working With Dates and Times in VBScript
    - Designing WCF DataContract Classes Using the...
    - Understanding Dates and Times in VBScript
    - Working With Arrays in VBScript
    - Compressed Folders in WSH
    - Using .NET Interops in VBScript
    - Nilpo`s Scripting Secrets, Vol I
    - Database operations using Silverlight 2.0 WC...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    Stay green...Green IT