Search code examples
phptimewmiutc

Convert WMI UTC time to unix time stamp using PHP


I'm using PHP to make a WMI query to remote computers in my network.

I'm getting the LastBootupTime value using this:

$wmi_operatingsystem = $obj->ExecQuery("Select * from Win32_OperatingSystem"); 
$lastreboot = $wmi_call->LastBootupTime;

My issue is that $lastreboot is something like 20130612032422.112393-360. I need to convert this value to a unix time stamp or something human friendly. From what I've read I believe that's a time stamp in UTC format. I've tried using strtotime, but that's not working for me.

HELP!


Solution

  • You can use the SWbemDateTime object to decode the UTC format.

     $wtime = new COM ("WbemScripting.SWbemDateTime");  
     $wtime->Value = $wmi_call->LastBootupTime;
     //Now you can access the elements of the datetime using the SWbemDateTime properties  
     //like so $wtime->Year,$wtime->Month,$wtime->Day