Register
: :
Login
Home
News
Forums
Scripts
User Groups
Resources
About
Forums
Search
Members
Unanswered
Active Topics
Forums
>
Using PowerShell
>
General PowerShell
How To Do A Date Comparison In Powershell
Last Post 21 Feb 2012 09:14 AM by
DaveS
. 2 Replies.
Sort:
Oldest First
Most Recent First
Prev
Next
You are not authorized to post a reply.
Author
Messages
DaveS
New Member
Posts:24
21 Feb 2012 08:38 AM
Hi,
I wondered if anyone can help me with the following code:
If I have a date field which is defined as a string in the format "dd-mm-yyyy", what is the code to check whether this date is older than or equal to six months from todays date ?
Thanks in advance.
EBGreen
Veteran Member
Posts:1089
21 Feb 2012 08:46 AM
Here are a couple of examples to give you an idea and you can work out exactly what you need from them:
(Get-Date).AddMonths(-6) -lt (Get-Date "12-12-2011")
True
(Get-Date).AddMonths(-2) -lt (Get-Date "12-12-2011")
False
"Look Ma...no strings!"
DaveS
New Member
Posts:24
21 Feb 2012 09:14 AM
Thanks very much - that did it.
You are not authorized to post a reply.
Using PowerShell
--General PowerShell
--Books, Tools, and Videos
--Exchange Server
--Active Directory
--System Center Family
--Non-Microsoft Products
--SharePoint
--SQL Server
--Working with .NET
--Peer Review
--Testing, Testing...
PowerShell Development
--Cmdlet Development
--PSDrive Provider Development
--Hosting the Shell
Looking Ahead
--Using PowerShell v2.0
--Developing for PowerShell v2.0
PowerShellCommunity.org
--Community Announcements and Assistance
--Completely Unrelated
--User Groups
--Community Business
----Suggestion Box
Forums
>
Using PowerShell
>
General PowerShell
Active Forums 4.3
Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2