Powershell – Get the First and Last Day of the Month

You could do this in different ways with powershell. But the whole idea is to keep it simple

$CURRENTDATE=GET-DATE -Format "MM/dd/yyyy"
$FIRSTDAYOFMONTH=GET-DATE $CURRENTDATE -Day 1
$LASTDAYOFMONTH=GET-DATE $FIRSTDAYOFMONTH.AddMonths(1).AddSeconds(-1)

$FIRSTDAYOFMONTH
$LASTDAYOFMONTH
Advertisements

About Sunil Padmanabhan

An Indian based out of Dubai who started traveling from 2011 and pretty much caught the travel bug. Every year presents itself as an opportunity to visit and explore a new place.

Posted on March 31, 2015, in Powershell and tagged . Bookmark the permalink. 1 Comment.

  1. Thanks for the point in the right direction. I used this to keep it simple.

    $StartDate = ((get-date -day 1).addmonths(-1)).ToShortDateString()
    $EndDate= ((get-date -day 1).adddays(-1)).ToShortDateString()

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: