PowerShell:按月比较DateTime?

PowerShell:按月比较DateTime?,datetime,compare,powershell-2.0,Datetime,Compare,Powershell 2.0,在PowerShell 2.0中,按月份比较日期时间的正确方法是什么?最后,我想知道当前月份是7月还是更晚,在7月和12月之间。年份不重要。我不确定是否有针对特定月份的比较的切换,或者尝试只获取月份和>=7。谢谢这样可以帮助你: C:\ps> [datetime]::Today.Month -gt ([datetime]"12/01/2012").month False C:\ps> [datetime]::Today.Month -gt ([datetime]"07/12/201

在PowerShell 2.0中,按月份比较日期时间的正确方法是什么?最后,我想知道当前月份是7月还是更晚,在7月和12月之间。年份不重要。我不确定是否有针对特定月份的比较的切换,或者尝试只获取月份和>=7。谢谢这样可以帮助你:

C:\ps> [datetime]::Today.Month -gt ([datetime]"12/01/2012").month
False

C:\ps> [datetime]::Today.Month -gt ([datetime]"07/12/2012").month
True
比较日期可以是任何您想要的,只是用于比较的月份

这同样可以做到:

C:\ps> [datetime]::Today.Month -gt 7
    False


C:\ps> [datetime]::Today.Month -gt 7
True

我将使用名为Get-Date的PowerShell cmdlet

If ((Get-Date).Month -ge 7){...}