O'Reilly logo

Microsoft® SQL Server 2012 Unleashed by Alex T. Silverstein, Chris Gallelli, Paul T. Bertucci, Ray Rankins

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Dealing with Dates and Times

Being able to do date/time calculations is very useful. Fortunately PowerShell provides all kinds of quick date/time calculations. Some of the more common tricks are shown in the following example:

PS>[DateTime]::NowTuesday, August 05, 2012 2:01:22 PMPS>([DateTime]::Now).AddDays(-1)Monday, August 04, 2012 2:01:44 PMPS>

Here, a .NET method is used to get a new value from the original object. This is done in a “single step,” in contrast to saving the object to a variable and then using the method on the variable. The use of a minus sign indicates that a value is being requested from the past.

Other common date/time methods include the following:

AddHours—Add/subtract based on a number ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required