string to datetime

hi all,

I read the Installdate value from win32_operatingsystem and that gives me a string like;


how can I convert this to a human readable date?


Depending on how exact you need to be, you could do the following:

$date = "20190308145131.000000-240" -split "\." | Select -first 1

get-date $([int64]$date)

Here’s another way how you can do it.

Get-WmiObject Win32_OperatingSystem | select @{N=‘ReadableInstallDate’;E={ $.ConvertToDateTime($.InstallDate) }}

thanks, guys!

Hmm, those give 2 different answers. How about

(Get-CimInstance Win32_OperatingSystem).InstallDate

I don’t think Will’s answer is correct for wmi time. The epoch is different.

Yeah, there’s a method embedded in the WMI class object you get back to convert it to a proper datetime, but it’s a lot easier to use Get-CimInstance, where that work is done for you. :slight_smile: