POLLOX
POLLOX

Reputation: 302

Date format problems

I´m trying to get the month with 05 format.

I´m executing:

PS C:\Users\olopez> (Get-date).adddays(-1).month
5
PS C:\Users\olopez>

How can I change the 5 format to 05?

I have tried with something like this:

PS C:\Users\olopez> $a= get-date -format d ((get-date).adddays(-1))
PS C:\Users\olopez>  $a=Get-date -format dd-MM-yyyy
PS C:\Users\olopez> [datetime]::parseexact($a,"dd-MM-yyyy",$null)

Thursday, May 22, 2014 12:00:00 AM


PS C:\Users\olopez> [datetime]::parseexact($a,"dd-MM-yyyy",$null).month
5
PS C:\Users\olopez>

Obiously it returns 5 again :).

Thanks in advance

Upvotes: 0

Views: 32

Answers (2)

CB.
CB.

Reputation: 60976

try this:

(Get-date).adddays(-1).ToString("MM")

Upvotes: 2

James Woolfenden
James Woolfenden

Reputation: 6681

Like this?

get-date -format MM

Returns 05

Upvotes: 0

Related Questions