Powershell Get-Date
Olivia Zamora
I am creating an object in a powershell script that gets today date in the following format.
$TodaysDate=Get-Date -Format "MM-MMM"The result shows the month as both a numeric value as well as the name value:
$TodaysDate
04-AprIs there a way I can take that value and somehow change the first to digits to a different value and then store that as a new object?
Example:
01-Jan Would become 04-Jan
02-Feb Would become 05-Feb
03-Mar Would become 06-Mar
04-Apr Would become 07-Apr
and so on .....
41 Answer
A bit annoying that -Format returns a string, rather than a DateTime with a specific format. Maybe, get each element separately, add three months to the first element, then get the string of each one and concatenate them:
(Get-Date ((Get-Date).AddMonths(3)) -Format "MM") + "-" + (Get-Date -Format "MMM")Or something like that.
This also a really awkward date format. Accountants are weird.
1