PowerTip: Find Number of Hours in Number of Days

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


Comments (0)

Skip to main content