December 9th, 2014

PowerTip: Use PowerShell to Determine Weeks Between Dates

Doctor Scripto
Scripter

Summary: Use Windows PowerShell to determine the number of weeks between two dates.

Hey, Scripting Guy! Question I have a project that is broken into several major components of work. I know the start date of the project and
           the end date of the project. How can I use Windows PowerShell to determine the number of weeks between
           these dates so I can determine how many weeks to allocate for each milestone?

Hey, Scripting Guy! Answer Use the New-TimeSpan cmdlet to create a timespan object that represents the amount of time between
           the start date and the end date. Then divide the Days property by seven to determine the number of weeks.
           Here is an example:

PS C:\> $ts = New-TimeSpan -Start 1/5/2015 -End 5/25/15 

PS C:\> $ts.Days / 7

20

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