June 18th, 2014

PowerTip: Add Days, Hours, and Minutes to Current Time

Doctor Scripto
Scripter

Summary: Use Windows PowerShell to easily add days, hours, and minutes to the current time.

Hey, Scripting Guy! Question How can I use Windows PowerShell to add one day, two hours, and thirty minutes to the current date and time?

Hey, Scripting Guy! Answer Create a TimeSpan object that represents one day, two hours, and thirty minutes,
          then add it to the current date and time that Get-Date retrieves:

$ts = New-TimeSpan -Days 1 -Hours 2 -Minutes 30

(get-date) + $ts

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.