0

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"
Avshalom
  • 8,657
  • 1
  • 25
  • 43
hdsouza
  • 354
  • 4
  • 17
  • 1
    Possible duplicate of [How to format a DateTime in PowerShell](https://stackoverflow.com/questions/2249619/how-to-format-a-datetime-in-powershell) – Guenther Schmitz Mar 11 '19 at 14:08

1 Answers1

2

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

(Get-Date).adddays(-1).ToString("yyyyMMdd")
TobyU
  • 3,718
  • 2
  • 21
  • 32