Powershell – Getting Formatted Date Info

This is a simple one, want to get today, yesterday, last month or last year .. try this

$Date = Get-Date
$Today = $Date | Get-date -Format MM/dd/yyyy
$Yesterday = $Date.AddDays(-1) | Get-Date -Format MM/dd/yyyy
$LastMonth = $Date.AddMonths(-1) | Get-date -Format MM/dd/yyyy
$LastYear = $Date.AddYears(-1) | Get-Date -Format MM/dd/yyyy

You get the idea .. get last 6 months:
$Last6Months = $Date.AddMonths(-6) | Get-date -Format MM/dd/yyyy

Bookmark the permalink.

Comments are closed.