September 22nd, 2015

PowerTip: Find Number of Hours in Number of Days

Doctor Scripto
Scripter

Summary: Use Windows PowerShell to find the number of hours in a number of days.

Hey, Scripting Guy! Question How can I use Windows PowerShell to easily figure out how many hours are in 30 days without
           doing any multiplication?

Hey, Scripting Guy! Answer Use New-TimeSpan to create a timespan object for 30 days. The output will tell the number of hours,
           minutes, and seconds in the timespan. Here is an example:

New-TimeSpan -Days 30

To return only the number of hours, retrieve the TotalHours property:

PS C:\> (New-TimeSpan -Days 30).totalhours

720

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