header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
How To Do A Date Comparison In Powershell
Last Post 21 Feb 2012 09:14 AM by DaveS. 2 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
DaveSUser is Offline
New Member
New Member
Posts:24
Avatar

--
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.
    EBGreenUser is Offline
    Veteran Member
    Veteran Member
    Posts:1089
    Avatar

    --
    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!"
    DaveSUser is Offline
    New Member
    New Member
    Posts:24
    Avatar

    --
    21 Feb 2012 09:14 AM

    Thanks very much - that did it.

     

    You are not authorized to post a reply.


    Active Forums 4.3
    right
    footer   footer
    footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2 footer
    footer   footer