hdsouza
hdsouza

Reputation: 355

Substract a date with Powershell

Using Powershell I need to get a date in the "yyyyMMdd" format. I can use $Date_Today = Get-Date -format "yyyyMMdd" and it works corerctly.

Now I need to get the date, a day ago:

(Get-Date).adddays(-1)

But If I need to get the date , a day ago in the same format I get an error:

((Get-Date).adddays(-1)) -format "yyyyMMdd"

Upvotes: 0

Views: 204

Answers (1)

TobyU
TobyU

Reputation: 3908

Use the .ToString() function to get the desired result:

(Get-Date).adddays(-1).ToString("yyyyMMdd")

Upvotes: 2

Related Questions