I'm trying to convert string variable to datetime format:
[DateTime]::ParseExact($tempdate, 'dd.MM.yyyy', [CultureInfo]::InvariantCulture).ToString('yyMMdd')
$tempdate contains date in format dd.MM.yyyy which was obtained from an Excel file.
Unfortunately I'm getting error message:
Exception calling "ParseExact" with "3" argument(s): "String was not recognized as a
valid DateTime."
At line:1 char:1
+ [DateTime]::ParseExact($tempdate, 'dd.MM.yyyy', [CultureInfo]::Invaria ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : FormatException
It works fine when I put 'clean date' instead of variable.
[DateTime]::ParseExact('13.03.2017', 'dd.MM.yyyy', [CultureInfo]::InvariantCulture).ToString('yyMMdd')
What is wrong with this variable or how can I convert it to datetime in other way?
$tempdate? - Ansgar Wiechers$tempdate. Does the linked question from wOxxOm help? What is the current type?$tempdate.GetType().Fullname. Are there any leading or trailing spaces?"'$tempdate'"- Matt