December 28th, 2013

PowerTip: Get Time Difference between Dates with PowerShell

Doctor Scripto
Scripter

Summary: Use New-TimeSpan to produce the time difference between two dates.

Hey, Scripting Guy! Question I know I can subtract dates, but is there a Windows PoweShell cmdlet to show me the time difference between dates?

Hey, Scripting Guy! Answer Use New-TimeSpan and supply the information!
          For example, to show the difference between today and the upcoming New Year:

$StartDate=(GET-DATE)

$EndDate=[datetime]”01/01/2014 00:00”

NEW-TIMESPAN –Start $StartDate –End $EndDate

Author

The "Scripting Guys" is a historical title passed from scripter to scripter. The current revision has morphed into our good friend Doctor Scripto who has been with us since the very beginning.

2 comments

Discussion is closed. Login to edit/delete existing comments.

Newest
Newest
Popular
Oldest
  • Jens Vestergaard

    Somethings fishy with the img references on this blog :/

  • M13 IO

    Glad I found this oldie but goodie!!!  ‘

Feedback