Get-Date -Format FileDateTime
gives something like this:
20211027T1306219297
Is it possible to import such a string into a datetime variable? Something like?
$date = Get-Date "20211027T1306219297"
CodePudding user response:
You can use [datetime]::ParseExact
method with yyyyMMddTHHmmssffff
as format argument.
$date = [datetime]::ParseExact("20211027T1306219297", 'yyyyMMddTHHmmssffff', $null)
This is because FileDateTime
internally uses yyyyMMddTHHmmssffff
format which is documented here.
FileDateTime.
A file or path-friendly representation of the current date and time in local time, in 24-hour format. The format is
yyyyMMddTHHmmssffff
(case-sensitive, using a 4-digit year, 2-digit month, 2-digit day, the letter T as a time separator, 2-digit hour, 2-digit minute, 2-digit second, and 4-digit millisecond). For example: 20190627T0840107271.