Duplicate question. See https://learn.microsoft.com/en-us/answers/questions/1185644/parseexact-with-3-argument(s)-string-was-not-recog
A community member has associated this post with a similar question:
"ParseExact" with "3" argument(s): String was not recognized as a valid DateTime
Only moderators can edit this content.
"ParseExact" with "3" argument(s): String was not recognized as a valid DateTime
Hi team,
I am trying to calculate the number of days between two dates and store in a new variable. But when I run the script it shows the following error ""ParseExact" with "3" argument(s): String was not recognized as a valid DateTime".
Here is the script that I am using:
$ValidFrom = "Sep 14 18:15:31 AEST 2022"
$ValidTo = "Sep 14 18:15:31 AEST 2023"
$startDateObj = [datetime]::ParseExact($ValidFrom, "MMM dd HH:mm:ss AEST yyyy", $null)
$endDateObj = [datetime]::ParseExact($ValidTo, "MMM dd HH:mm:ss AEST yyyy", $null)
$daysBetween = ($endDateObj - $startDateObj).Days
Here is a screenshot of the error that is displayed in Newrelic. (Please done worry about the line number since the powershell script has other variables in it). The error occurs only when I calculate the dates.
Thanks!