Accessing Date Methods

by Dec 24, 2008

While Get-Date returns the current date and time, it really returns a DateTime object. You can use this object to find out more about the date or to calculate date and time offsets as it has a number of very useful properties and methods.

$date = Get-Date

For example, to find out if Daylight Savings Time is in effect:

$date.IsDaylightSavingTime()

Or, try adding 10 days from today:

$date.AddDays(10)

Next, go back 5 days:

$date.AddDays(-5)

Hint: Use PowerShellPlus to get automatic code completion. Once you type the ".", you will see all the properties and methods an object exposes.