Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert WMI DateTime to standard DateTime?

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?

like image 649
Remus Rigo Avatar asked Dec 30 '22 07:12

Remus Rigo


2 Answers

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

like image 172
RRUZ Avatar answered Feb 08 '23 22:02

RRUZ


MagWMI from Magenta Systems contains MagWmiDate2DT() that does this.

http://www.magsys.co.uk/delphi/magwmi.asp

like image 25
davea Avatar answered Feb 09 '23 00:02

davea