Powershell Get-Date

Powershell Get-Date

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-Apr

Is 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 .....

4

1 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Alexander Ross
Author

Alexander Ross

Alexander Ross has covered the video game industry for a decade, writing deep dives on game design, esports tournaments, VR developments, and gaming culture.