Ariel
Ariel

Reputation: 978

Formatting date month in PowerShell

I need to format the previous date to yyyy-mm-dd.

For example, today is May 25,2016. Therefore I need the output '2016-05-24'.

$a = (Get-Date).AddDays(-1).ToString('yyyy-mm-dd')
Write-Output $a

When I run the code I get 2016-44-24 which is incorrect.

How can I do it?

Upvotes: 2

Views: 833

Answers (1)

Martin Brandl
Martin Brandl

Reputation: 58931

mm specifies The minute, from 00 through 59 Source.

You have to use uppercase for month instead:

(Get-Date).AddDays(-1).ToString('yyyy-MM-dd')

Upvotes: 4

Related Questions