Here’s how to programmatically get the last day of last month in PowerShell:
1 2 3 |
(get-date).adddays(-(get-date -format dd)) |
To get the last day of this month, this will work:
1 2 3 |
((get-date).addmonths(1)).adddays(-(get-date ((get-date).addmonths(1)) -format dd)) |
Perfect. Thanks. But how could I get the same information without the “hour”.
Thanks again
Mar
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.
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.
This is pretty straightforward. If you have your date saved as
$date
, then$date.tostring("dddd")
will give you the day, eg: Sunday.