Showing posts with label Get-Date. Show all posts
Showing posts with label Get-Date. Show all posts

Saturday, April 21, 2018

Calculate the Difference Between Dates with PowerShell

With PowerShell, it's easy to calculate the difference between dates:

$StartDate = Get-Date
$EndDate = [datetime]"10/31/2018"
New-TimeSpan -Start $StartDate -End $EndDate









Thus, we can see that it's over 192 days until the next Halloween.

Monday, February 5, 2018

Find the Day of the Year

The easiest way to use PowerShell to get the date is--surprise!--Get-Date:

Get-Date

 


But that output is not a string of text. It's an object, with properties that can be searched for, extracted, and manipulated. For example, how many days into the year are we on today's date?

(Get-Date).DayOfYear

 


My how the days fly by.