Windows Vista Forums

simple date requirement
  1. #1


    Neil Townsend Guest

    simple date requirement

    Hi - Powershell newbie here!

    I need to do something simple, but I just can't get it right in Powershell.

    i need to read in the date from a file and compare it to todays date. Simple. Only thing is i want to compare just the date - ie not the time.

    Currently i have something like the following:



    $variable = get-date -format(dd/MM/yyyy)
    $var = dir c:\anyfolder\anyfile.txt |where-object {$_.lastwritetime |select lastwritetime}

    but it won't give me what i want. Haven't done the comparison here!
    i just need the date in dd/MM/YYYY format as variables from a file and from the machine date.

    Any help greatly appreciated.

    Thnx


    Submitted via EggHeadCafe - Software Developer Portal of Choice
    Object-Relational Mapping as a Persistence Strategy
    http://www.eggheadcafe.com/tutorials...l-mapping.aspx

      My System SpecsSystem Spec

  2. #2


    Karl Mitschke Guest

    Re: simple date requirement

    Hello Neil,

    > Hi - Powershell newbie here!
    >
    > I need to do something simple, but I just can't get it right in
    > Powershell.
    >
    > i need to read in the date from a file and compare it to todays date.
    > Simple. Only thing is i want to compare just the date - ie not the
    > time.
    >
    > Currently i have something like the following:
    >
    > $variable = get-date -format(dd/MM/yyyy)
    > $var = dir c:\anyfolder\anyfile.txt |where-object {$_.lastwritetime
    > |select lastwritetime}
    > but it won't give me what i want. Haven't done the comparison here! i
    > just need the date in dd/MM/YYYY format as variables from a file and
    > from the machine date.
    >
    > Any help greatly appreciated.
    >
    > Thnx
    >
    > Submitted via EggHeadCafe - Software Developer Portal of Choice
    >
    > Object-Relational Mapping as a Persistence Strategy
    >
    > http://www.eggheadcafe.com/tutorials...0-4748-b42d-02
    > 7f7a228063/objectrelational-mapping.aspx
    >
    I am not sure exactly what you are looking for, but try this:

    $variable = (get-date).ToShortDateString()
    $var = ls *.txt | Where-Object {$_.lastwritetime.ToShortDateString() -eq
    $variable}

    If that works, you can change it to:

    $var = ls *.txt | Where-Object {$_.lastwritetime.ToShortDateString() -eq
    (get-date).ToShortDateString()}

    Karl
    http://unlockpowershell.wordpress.com/



      My System SpecsSystem Spec

simple date requirement problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
SP2 requirement Martin Racette Vista General 4 08 Jun 2009
Modified Date used as Date Taken in Photo Gallery and Digital Imag MarkDav Vista music pictures video 0 16 Feb 2008
ACPI requirement Eric Vista installation & setup 3 29 Nov 2006
more requirement q's.. sry dale Vista General 6 11 Jun 2006
more requirement q's.. sry dale Vista General 0 11 Jun 2006