WillG771
WillG771

Reputation: 55

Converting Date String (31-Jan) to date (MM/DD)

I have an AD property that contains birthdays in the format of DD-MMM (31-Jan). I need to query this via powershell and return it as 01/31. I have attempted ParseExact, 31-Jan is not recognized as a valid date format.

Thanks in advance for any help I am a powershell novice. What am I missing here.

Upvotes: 0

Views: 63

Answers (3)

Mark Wragg
Mark Wragg

Reputation: 23355

You can also do:

Get-Date '31-Jan' -f 'MM/dd'

Upvotes: 2

Kory Gill
Kory Gill

Reputation: 7163

You can just use Parse.

Example:

[DateTime]::Parse("31-jan").ToString("MM/dd")

I would think this should get you unblocked.

Upvotes: 2

Bill_Stewart
Bill_Stewart

Reputation: 24535

Why not just

"{0:MM/dd}" -f (Get-Date 31-Jan)

?

Upvotes: 3

Related Questions