date formats

  • ((Get-Date).AddMonths(1))
    gives me
    Saturday, August 25, 2018 3:06:26 AM

    (Get-Date -format 'Y')
    gives me
    July, 2018

    How do  i get August, 2018 when I run code  in the month of July with the output in this format
    August, 2018

    Thanks

  • mtz676 - Wednesday, July 25, 2018 4:09 AM

    ((Get-Date).AddMonths(1))
    gives me
    Saturday, August 25, 2018 3:06:26 AM

    (Get-Date -format 'Y')
    gives me
    July, 2018

    How do  i get August, 2018 when I run code  in the month of July with the output in this format
    August, 2018

    Thanks

    Try something along the lines of:
    $SomeDate = (Get-date).AddMonths(1)
    Get-Date $SomeDate -Format 'Y'

    Sue

  • PowerShell uses the .NET format for date and time. You can look at https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-date-and-time-format-strings to see how t to use the build in standard formats. If you need something more custom, use this: https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings.

  • mtz676 - Wednesday, July 25, 2018 4:09 AM

    ((Get-Date).AddMonths(1))
    gives me
    Saturday, August 25, 2018 3:06:26 AM

    (Get-Date -format 'Y')
    gives me
    July, 2018

    How do  i get August, 2018 when I run code  in the month of July with the output in this format
    August, 2018

    Thanks

    Ummm... use T-SQL instead? 😀

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Jeff Moden - Friday, February 22, 2019 11:32 AM

    mtz676 - Wednesday, July 25, 2018 4:09 AM

    ((Get-Date).AddMonths(1))
    gives me
    Saturday, August 25, 2018 3:06:26 AM

    (Get-Date -format 'Y')
    gives me
    July, 2018

    How do  i get August, 2018 when I run code  in the month of July with the output in this format
    August, 2018

    Thanks

    Ummm... use T-SQL instead? 😀

    Odd as it may seem, a lot of times when someone posts a Powershell question in the Powershell forum they are often looking for an answer in Powershell. 
    Imagine that 🙂

  • Jeff Moden - Friday, February 22, 2019 11:32 AM

    mtz676 - Wednesday, July 25, 2018 4:09 AM

    ((Get-Date).AddMonths(1))
    gives me
    Saturday, August 25, 2018 3:06:26 AM

    (Get-Date -format 'Y')
    gives me
    July, 2018

    How do  i get August, 2018 when I run code  in the month of July with the output in this format
    August, 2018

    Thanks

    Ummm... use T-SQL instead? 😀

    Powershell has better date formatting options than CONVERT 😛

  • ZZartin - Friday, February 22, 2019 11:56 AM

    Jeff Moden - Friday, February 22, 2019 11:32 AM

    mtz676 - Wednesday, July 25, 2018 4:09 AM

    ((Get-Date).AddMonths(1))
    gives me
    Saturday, August 25, 2018 3:06:26 AM

    (Get-Date -format 'Y')
    gives me
    July, 2018

    How do  i get August, 2018 when I run code  in the month of July with the output in this format
    August, 2018

    Thanks

    Ummm... use T-SQL instead? 😀

    Powershell has better date formatting options than CONVERT 😛

    "Better" how?

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Sue_H - Friday, February 22, 2019 11:52 AM

    Jeff Moden - Friday, February 22, 2019 11:32 AM

    mtz676 - Wednesday, July 25, 2018 4:09 AM

    ((Get-Date).AddMonths(1))
    gives me
    Saturday, August 25, 2018 3:06:26 AM

    (Get-Date -format 'Y')
    gives me
    July, 2018

    How do  i get August, 2018 when I run code  in the month of July with the output in this format
    August, 2018

    Thanks

    Ummm... use T-SQL instead? 😀

    Odd as it may seem, a lot of times when someone posts a Powershell question in the Powershell forum they are often looking for an answer in Powershell. 
    Imagine that 🙂

    Heh... I've been finding that, odd as it may seem, when someone posts a Powershell question in the Powershell forum, it's because they don't actually know enough about T-SQL nor how easy things can be there. 😀

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Sue_H - Wednesday, July 25, 2018 10:44 AM

    mtz676 - Wednesday, July 25, 2018 4:09 AM

    ((Get-Date).AddMonths(1))
    gives me
    Saturday, August 25, 2018 3:06:26 AM

    (Get-Date -format 'Y')
    gives me
    July, 2018

    How do  i get August, 2018 when I run code  in the month of July with the output in this format
    August, 2018

    Thanks

    Try something along the lines of:
    $SomeDate = (Get-date).AddMonths(1)
    Get-Date $SomeDate -Format 'Y'

    Sue

    Or

    (Get-Date).AddMonths(1).ToString("MMMM, yyyy")

    Far away is close at hand in the images of elsewhere.
    Anon.

Viewing 9 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic. Login to reply