Velvet Star Monitor

Standout celebrity highlights with iconic style.

news

Powershell Get-Date

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

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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