Convert DateTime string back into DateTime

Powershell

Convert DateTime string back into DateTime

In a script I was writing a time stamp to a file, when the script ran again I wanted to check that the time was more than 24 hours. I used the following to convert the string back to a datetime.

1
2
3
$dateTime = get-date -Format yyyyMMddhhmmss
 
[datetime]::ParseExact($dateTime,"yyyyMMddhhmmss",$null)

Source: http://msdn.microsoft.com/en-us/library/w2sa9yss.aspx

Leave a Reply

Your email address will not be published. Required fields are marked *