Have you ever wondered on how to convert string data type to datetime in PS?
In one of my PowerShell projects I need to compare couple of dates to get the exact difference. But some of date values are coming from different sources, for instance as a string.
Therefore i could not simply use “date2 – date1″ math operation.
It's pretty easy to convert a string to a datetime with Parseexact as follow:
$Date= [datetime]::ParseExact($StringDate,”dd.MM.yyyy HH:mm:ss”,$null)