In powershell I have a date that I expect is a string and another that I created for debugging purposes which is a string.
function ParseDate {
param
(
$inputDate #when debugging this outputs - 04/11/2021 23:00
)
$date = "04/11/2021 23:00" #hard coded for debugging
$parsedDate = [DateTime]::MinValue;
# $date here, which I had for debugging, $inputDate will fail for parse
$parsedSuccessfully = [DateTime]::TryParseExact($date, "dd/MM/yyyy HH:mm", $null, [System.Globalization.DateTimeStyles]::None, [ref] $parsedDate);
return $parsedDate
}
If I parse the hardcoded date ($date) then it works fine, but if I parse the $inputDate it fails and $parsedSuccessfully will be false.
If I output the GetType() on both objects then it returns the same type -
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True String System.Object
Is there any way to tell what the difference is between the inputDate and hard coded date as something must be different as one works and the other does not.