Delphi – How to convert WMI DateTime to standard DateTime

datetimedelphiwmi

I'm trying to read the install date from WMI (Win32_OperatingSystem.InstallDate). The return value looks like this: 20091020221246.000000+180. How can I get a valid Date?

Best Answer

Instead of parsing and extracting the values manually (how the accepted answer suggest), you can use the WbemScripting.SWbemDateTime object.

check this sample

function  WmiDateToTDatetime(vDate : OleVariant) : TDateTime;
var
  FWbemDateObj  : OleVariant;
begin;
  FWbemDateObj  := CreateOleObject('WbemScripting.SWbemDateTime');
  FWbemDateObj.Value:=vDate;
  Result:=FWbemDateObj.GetVarDate;
end;

For more info about this topic you can read this artile WMI Tasks using Delphi – Dates and Times