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

Balaji Raju Mohan 0 Reputation points
2023-03-02T00:06:20.36+00:00

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.

Screenshot 2023-03-02 at 11.03.40

Thanks!

Windows for business Windows Server User experience PowerShell
Windows for business Windows Server User experience Other
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. MotoX80 36,291 Reputation points
    2023-03-02T00:52:43.22+00:00
    0 comments No comments