PowerShell for Windows Admins

Jul 7 2015   5:47AM GMT

Number of working days

Richard Siddaway Richard Siddaway Profile: Richard Siddaway


Need to know the number of working days left until a specific date?

$we = [System.DayOfWeek]::Saturday, [System.DayOfWeek]::Sunday

$date = Get-Date -Year 2015 -Month 8 -Day 28
$now = (Get-Date).AddDays(-1)

$workdays = 0

while ($now -le $date){

$now = $now.AddDays(1)

if ($now.DayOfWeek -notin $we ) {


Create a collection of days you don’t want counting – in my case Saturday & Sunday

Set the date you want to count to and current date – the –1 on current day is to set the variable for the loop

In the loop increment the date and test against you collection of excluded days. Increment your workday counter and loop.

Now you can work out how many days until that holiday, course or whatever. The end date is included in the count by the way.

1  Comment on this Post

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.
  • bomark
    Works great, thanks!
    0 pointsBadges:

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: