PowerTip: Displaying Only the Current Year in PowerShell

PowerTip: Displaying Only the Current Year in PowerShell

  • Comments 9
  • Likes

Summary: Learn how to display only the current year.

Hey, Scripting Guy! QuestionHow can I use Windows PowerShell to display only the current year?

Hey, Scripting Guy! Answer

  1. get-date -Format yyyy

  2. get-date –format yy

  3. get-date –f yyyy

  4. (Get-Date).year

  5. Get-Date -UFormat %Y

  6. Get-Date -UFormat %

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
  • "Double, double toil and trouble; Fire burn, and caldron bubble"

    It's witchcraft...

    More magic from everybodies favorite mad scientist.

  • @jrv: Magic Ed Wilson @ work ...

    The wizard of South Carolina :-)

    As Teresa told me, "Date and time voodoo" is one of his hobbies

    besides diving, wood working and (underwater) photography

    Klaus.

  • Hi

    for fun:

    PS> ( date ).ToString('yyyy')

    PS> [datetime]::Today.Year

    PS> (Get-WmiObject Win32_LocalTime).Year

    PS>

  • @Walid - I'll see you and raise you one:

    (date).Year

  • @JRV hehehe

    @K_Schulte thanks ...

    @Walid Toumi these are great ... thanks for sharing.

    @JRV cool. Thanks.

    @JRV @Walid Toumi can you explain WHY Date works? It is not a cmdlets, nor it is a function or an alias!

  • @IamMred

    all cmdlet with verb "get" works

    childitem

    item

    service

    only get-process and get-command don't work

    because proccess is a special keyword "help keyword"

    and command is old shell win command.com

    sorry for my english

  • @Walid - good explanation and your english is fine.

    I learned somthing here today.  Thank you Walid and Ed.

    What you have pointed out is this:

    PS>function get-year{date -uf %Y}

    PS>year

    2012

  • And remember that these might give a different result to

    [DateTime]::UtuNow.Year

  • @all one of the great things about PowerShell is that is simplifies working with dates. In other languages I have used, datetime manipulation was always a major pain. I still remember old databases that had one column for month, another column for day, and another column for year. UGH!!!