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

  2 Responses to “Powershell: Playing With Dates”

  1. Your month is set to your minutes. “17”

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)