Creating Relative Dates

To create relative dates like "10 days ago," there are two paths. Administrators often add or remove time spans created by New-Timespan:

(Get-Date) - (New-TimeSpan -days 10)

Developers prefer object methods:

(Get-Date).AddDays(-10)

Both approaches will yield you the same result.

Twitter This Tip! ReTweet this Tip!


Posted Jun 11 2010, 08:00 AM by ps1
Concentrated Tech NSoftware Dell Compellent Sponsored by Idera and Concentrated Tech and NSoftware and Dell Compellent
Copyright 2011 PowerShell.com. All rights reserved.