Skip to content

Instantly share code, notes, and snippets.

@HighLibrarian
Created July 1, 2025 10:03
Show Gist options
  • Select an option

  • Save HighLibrarian/401f4b39273d8641f741d013db56d0ef to your computer and use it in GitHub Desktop.

Select an option

Save HighLibrarian/401f4b39273d8641f741d013db56d0ef to your computer and use it in GitHub Desktop.
get working hours in the current month
$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