How do I get the last day of the month with PowerShell?

green

Here’s how to programmatically get the last day of last month in PowerShell:

 

To get the last day of this month, this will work:

 green

4 Comments How do I get the last day of the month with PowerShell?

    1. Kamal

      Sure – if it’s just to display (and not for date-based calculations) just append something like:

      .tostring(“dd-MM-yyyy”)

      Or:

      .tostring(“yyyyMMdd”)

      You can format that pretty much anyway you want it to look.

      Reply
  1. Pallav Kumar

    Thanks for the post Kamal. I want to get the week day of last day of month. So for example for 30 Sep 2018, I want the value Sunday.

    Thanking in advance.

    Reply
    1. Kamal

      This is pretty straightforward. If you have your date saved as $date, then $date.tostring("dddd") will give you the day, eg: Sunday.

      Reply

Leave a Reply to Kamal Cancel reply

Your email address will not be published. Required fields are marked *