Determine Start Date of New Year

This topic contains 4 replies, has 4 voices, and was last updated by Profile photo of Dan Potter Dan Potter 10 months, 1 week ago.

  • Author
  • #33017
    Profile photo of Slade Benda
    Slade Benda

    Im trying to make a calendar program with powershell using PSExcel and im trying to do it for any given year from 2000 to 2100. Not sure how i would exactly find the start date for any given year. Any tips?


  • #33020
    Profile photo of Bob McCoy
    Bob McCoy

    It's a little unclear what you're looking for. You could generate a DateTime object for the first of January for each year doing something like this ...

    $years = 2000..2100
    foreach ($yr in $years) 
        Get-Date -Day 1 -Month 1 -Year $yr -Hour 0 -Minute 0 -Second 0
  • #33033
    Profile photo of Dan Potter
    Dan Potter

    It's always been January 1st:-)

    (1991..2015) | % {[datetime]"1/1/$_"}

  • #33038
    Profile photo of Brian B
    Brian B

    I assume he means start day (Day of week) vs the actual date of Jan 1 🙂

    In case that is what is needed, quick/dirty single day of week retrieval, just pass it a date (1-1-2016 for instance) and get the DayOfWeek property:

    get-date 1-1-2016 | select -expandProperty DayOfWeek

  • #33039
    Profile photo of Dan Potter
    Dan Potter


    (1991..2015) | % {([datetime]"1/1/$_").dayofweek}

You must be logged in to reply to this topic.