Dec 292011
 

So I’ve recently been playing around with Powershell to do some scripts at work, and ran into this hurdle.
I had to get today’s date, minus 2 days from it, and then output it in a certain format.
After much mucking about, I finally found out how to do it.

Firstly, assign the date to a variable

$a = Get-Date

And then, I can subtract the days I need and format it at the same time, and assign it to the second variable.

$b = $a.AddDays(-2).toString("yyyy/MM/dd hh:mm")

And voila, I now have the date minus 2 days in the format I need.

2011/17/27 11:17

Share