October 2017
Intermediate to advanced
440 pages
11h 47m
English
The Get-Date command is the best first stop for converting strings into dates. Get-Date deals with a reasonable number of formats.
If, however, Get-Date is unable to help, the DateTime class has two static methods that may be used:
The format strings used by these methods are documented on MSDN:
https://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx
The ParseExact method accepts one or more format strings and returns a DateTime object:
$string = '20170102-2030' # Represents 1st February 2017, 20:30 [DateTime]::ParseExact($string, 'yyyyddMM-HHmm', (Get-Culture))
The culture, returned from Get-Culture, used previously, fills in the format provider argument.
The format string uses:
Read now
Unlock full access