Hi Guys, I am having a hard time getting any version of get-date to compare dates from a csv file<\/p>\n
I have a csv with dates in format M/d/yyyy spanning future dates and dates back a few years.<\/p>\n
I need to be able to load the dates from the csv column and if they are within 365 days of todays date or older write that row from the csv file to a new csv file.<\/p>\n
This is what I have but it give incorrect results<\/p>\n
$DFormat = “M/d/yyyy”
\n$CheckDate = get-date (Get-Date).AddDays(-365) -format $Dformat
\n$csv= import-csv F:\\software_master_2017.csv
\n$OutCsv = @()
\nForEach ($row in $csv) {
\n$oRowDate = [DateTime]::ParseExact($row.“End of support”, $DFormat, $null)
\nif ($CheckDate -lt $oRowDate) { $OutCsv += $row }
\n} $OutCsv | Export-Csv F:\\results.csv -NTI<\/p>","upvoteCount":3,"answerCount":3,"datePublished":"2017-11-06T19:21:27.000Z","author":{"@type":"Person","name":"fb97126","url":"https://community.spiceworks.com/u/fb97126"},"acceptedAnswer":{"@type":"Answer","text":"
I found the problem right after I posted
\nI needed to change from -365 to 365 and switch the compare form
\nif ($CheckDate -lt $oRowDate) to if ($oRowDate -lt $CheckDate )<\/p>","upvoteCount":2,"datePublished":"2017-11-06T19:39:06.000Z","url":"https://community.spiceworks.com/t/powershel-date-compare-issue/616798/2","author":{"@type":"Person","name":"fb97126","url":"https://community.spiceworks.com/u/fb97126"}},"suggestedAnswer":[{"@type":"Answer","text":"
Hi Guys, I am having a hard time getting any version of get-date to compare dates from a csv file<\/p>\n
I have a csv with dates in format M/d/yyyy spanning future dates and dates back a few years.<\/p>\n
I need to be able to load the dates from the csv column and if they are within 365 days of todays date or older write that row from the csv file to a new csv file.<\/p>\n
This is what I have but it give incorrect results<\/p>\n
$DFormat = “M/d/yyyy”
\n$CheckDate = get-date (Get-Date).AddDays(-365) -format $Dformat
\n$csv= import-csv F:\\software_master_2017.csv
\n$OutCsv = @()
\nForEach ($row in $csv) {
\n$oRowDate = [DateTime]::ParseExact($row.“End of support”, $DFormat, $null)
\nif ($CheckDate -lt $oRowDate) { $OutCsv += $row }
\n} $OutCsv | Export-Csv F:\\results.csv -NTI<\/p>","upvoteCount":3,"datePublished":"2017-11-06T19:21:27.000Z","url":"https://community.spiceworks.com/t/powershel-date-compare-issue/616798/1","author":{"@type":"Person","name":"fb97126","url":"https://community.spiceworks.com/u/fb97126"}},{"@type":"Answer","text":"
This should work as well<\/p>\n
$CheckDate = get-date (Get-Date).AddDays(-365) -format \"M/d/yyyy\"\n$csv = import-csv \"F:\\\\software_master_2017.csv\"\n$OutCsv = @()\n\nForEach ($row in $csv) {\n if ([datetime]($row.\"End of support\") -lt $CheckDate) {\n $OutCsv += $row\n }\n} \n\n$OutCsv | Export-Csv F:\\results.csv -NoTypeInformation\n<\/code><\/pre>","upvoteCount":0,"datePublished":"2017-11-06T19:45:47.000Z","url":"https://community.spiceworks.com/t/powershel-date-compare-issue/616798/3","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}}]}}