How to get the next business day in powershell?

Member

by deron , in category: Third Party Scripts , 2 months ago

How to get the next business day in powershell?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by jasen_gottlieb , 2 months ago

@deron 

You can use the following PowerShell script to get the next business day:

1
2
3
4
5
6
7
8
9
$today = Get-Date
$nextDay = $today.AddDays(1)

# Check if the next day is a weekend (Saturday or Sunday)
while ($nextDay.DayOfWeek -eq "Saturday" -or $nextDay.DayOfWeek -eq "Sunday") {
    $nextDay = $nextDay.AddDays(1)
}

Write-Output "Next business day is $nextDay"


This script first gets the current date and then adds one day to it. It then checks if the next day is a weekend (Saturday or Sunday) and if it is, it adds another day until it finds the next business day. Finally, it outputs the next business day.