How to get the next business day in powershell?

Member

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

How to get the next business day in powershell?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by jasen_gottlieb , 5 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.

Related Threads:

How to get the next day skipping the weekend using moment.js?
How to get start of day and end of day in moment.js?
How to get values for time intervals of hours in one day in sparql?
How to properly get day of the week (name) with moment.js?
How to get date string from day number and month number using moment.js?
How to get next month in PHP?