December 7th, 2013

PowerTip: Use PowerShell to Subtract Timespans

Doctor Scripto
Scripter

Summary: Subtract timespans by using Windows PowerShell.

Hey, Scripting Guy! Question How can I use Windows PowerShell to subtract 2 days and 14 hours from 12 days and 1 hour to determine the amount of time left on a project?

Hey, Scripting Guy! Answer Create two timespans using the New-Timespan cmdlet, and then subtract them from each other:

(New-TimeSpan -Days 12 -Hours 1) – (New-TimeSpan -Days 2 -Hours 14)

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.

0 comments

Discussion are closed.

Feedback