问题
I have the following test code. Basically I am checking when a new file is created in folder. I need to know that if the file was created after 4pm display the next business day. Currently my code displays the next day, but I need to display the next business day. Any help would be appreciated.
$formatteddate = "{0:h:mm:ss tt}" -f (get-date)
if ($formatteddate -gt "4:00:00 PM"){
$(Get-Date).AddDays(1).ToString('MMM d yyyy')
}
回答1:
Adding to what jisaak said: "business day" is organization specific. Some organizations don't work on holidays that other organizations do. If you want to handle holidays correctly you'll need an explicit list of holidays for your business
Omitting the formatting details (which OP seems to understand) this should do it:
# $date is input date
$nextBizDay = $date.adddays(1)
# You would probably want to generate the follow list programmatically,
# instead of manually as done here
$holidays = 1, <# New Years #>
18, <# MLK day 2016 #>
<# other holidays encoded as Day Of Year #>
360 <# Christmas in a Leap Year #>
# An alternative to a list of holidays like this is to find a web service
# you can query to get the holidays for a given year
while ($nextBizDay.DayOfWeek -eq 'Saturday' -or
$nextBizDay.DayOfWeek -eq 'Sunday' -or
$nextBizDay.DayOfYear -in $holidays) {
if ($nextBizDay.DayOfYear -gt 366) {
throw "No next business day this year. Need to add additional logic"
}
$nextBizDay = $nextBizDay.adddays(1)
}
来源:https://stackoverflow.com/questions/37575352/how-to-get-the-next-business-day-in-powershell