Created
July 1, 2025 10:03
-
-
Save HighLibrarian/401f4b39273d8641f741d013db56d0ef to your computer and use it in GitHub Desktop.
get working hours in the current month
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $HoursPerDay = 8 | |
| # get our current date | |
| $StartDate = get-date | |
| # get the first day of the current month, then add 1 month the get the next month, and subtract 1 day | |
| # this will give you the last day of the current mont | |
| $EndDate = (get-date -day 1).AddMonths(1).AddDays(-1) | |
| $WorkingDays = 0 | |
| $CurrentDate = $StartDate.Date | |
| # we loop through each day from the start date to the end date and count the working days | |
| while ($CurrentDate -le $EndDate) | |
| { | |
| if ($CurrentDate.DayOfWeek -ne 'Saturday' -and $CurrentDate.DayOfWeek -ne 'Sunday') | |
| { | |
| $WorkingDays++ | |
| } | |
| $CurrentDate = $CurrentDate.AddDays(1) | |
| } | |
| # having your working days we can now calculate the total working hours | |
| $TotalWorkingHours = $WorkingDays * $HoursPerDay | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment