Random header image... Refresh for more!

Posts Tagged ‘Date and Time’

Subtract X Days from a DateTime Object using PowerShell

Icon Written by Niklas Goude on March 5, 2009 – 10:45 pm

Adding 10 or 100 days to a DateTime object is easy, you can simply use the AddDays() method.

PS > $Today = Get-Date
PS > $Today

Thursday, March 05, 2009 10:14:55 PM

PS > $Today.AddDays(10)

Sunday, March 15, 2009 10:14:55 PM

But how can we subtract Days??

There is a Subtract() method available through the System.DateTime Class, but we have to pass [...]

Tags: