[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 5815
  • Last Modified:

PowerShell command / script to get previous month

Q1:
I could get the current month with the command
below.  How do I get the previous month ie March ?

PS C:\Users\Art> Get-Date -format MMMM
April


Q2:
Likewise, how do I get previous & next day's date?

I'm on Win 2008 R2 and Windows 7 Profsnl : guess
it's the same PowerShell for both
0
sunhux
Asked:
sunhux
1 Solution
 
oBdACommented:
With the AddMonths() and AddDays() methods, for example like this:
$Today = Get-Date
$LastMonth = $Today.AddMonths(-1) | Get-Date -Format "MMMM"
$Yesterday = $Today.AddDays(-1)
$Tomorrow = $Today.AddDays(1)

Open in new window

You can pipe any object to Get-Member (or the "gm" alias) to find the methods supported. In this case: Get-Date | gm
0
 
sunhuxAuthor Commented:
Wonderful
0

Featured Post

New Tabletop Appliances Blow Competitors Away!

WatchGuard’s new T15, T35 and T55 tabletop UTMs provide the highest-performing security inspection in their class, allowing users at small offices, home offices and distributed enterprises to experience blazing-fast Internet speeds without sacrificing enterprise-grade security.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now