August 8th, 2014

PowerTip: Find How Many Days Are in a Month

Doctor Scripto
Scripter

Summary: Figure out how many days are in a month by using Windows PowerShell.

Hey, Scripting Guy! Question How can I use Windows PowerShell to find how many days are in a particular month?

Hey, Scripting Guy! Answer Use the DaysInMonth static method from the System.DateTime object.
            It expects the year and then the month as arguments. Here are a couple examples:

Days in October 2014:

[datetime]::DaysInMonth(14,10)

Days in February 2015:

[datetime]::DaysInMonth(2015,2)

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.