View Single Post
Old 01-07-2009   #1 (permalink)
NetTerry


 
 

Comparing dates with If

I'm trying to find directories more than 90 days old, but it looks like the
If comparison isn't working correctly. In this script the result should be
'True' but comes out 'False'. Suggestions?
# IfTest.ps1
# Test If on date comparison

# Get today's date and calculate the date 90 days ago
$Today = ( get-date ).ToString('MMddyyyy')
$90daysago = ( get-date ).AddDays(-90).ToString('MMddyyyy')

Write-Output $Today
Write-Output $90daysago

# Test difference in dates
If($90daysago -lt $Today)
{$Test = 'True'}
Else
{$Test = 'False'}

Write-Output "Today is later than 90 days ago: " $Test
--
Terry Edwards
My System SpecsSystem Spec