Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Well, my phone allows me to set which days are business days, but Windows/.NET won't, so I assume Monday through Friday.</p> <p>Note: As the question includes "golf" I am golfing this one, that is trying to use as few bytes for the script as possible. The code is not necessarily readable as a result.</p> <p>The easiest and most straightforward way to do is would be to start with today, add a day and look whether it is in the wanted range:</p> <pre><code>PS&gt; $d = [DateTime]::Now.AddDays(1); while ($d.DayOfWeek -eq "Saturday" -or $d.DayOfWeek -eq "Sunday") { $d = $d.AddDays(1) }; $d Montag, 22. Juni 2009 19:50:27 </code></pre> <p>We can shorten that a little, though:</p> <pre><code>PS&gt; $d=(Get-Date)+"1";for(;6,0-contains$d.DayOfWeek){$d+="1"}$d Montag, 22. Juni 2009 19:52:31 </code></pre> <p>But we can also try it differently, using the pipeline. The next business day is at least one and at most three days away, so we can generate a list of possible dates and filter them accordingly and at last, select the first one:</p> <pre><code>PS&gt; @(1..3|%{(Get-Date).AddDays($_)}|?{$_.DayOfWeek -ge "Monday" -and $_.DayOfWeek -le "Friday"})[0] Montag, 22. Juni 2009 22:11:19 </code></pre> <p>or shorter:</p> <pre><code>PS&gt; @(1..3|%{(Get-Date)+"$_"}|?{1..5-contains$_.DayOfWeek})[0] Montag, 22. Juni 2009 19:55:53 </code></pre> <p>By letting the range go to 4 we can guarantee that it always returns at least two workdays and save the @ operator to force an array:</p> <pre><code>PS&gt; (1..4|%{(Get-Date)+"$_"}|?{1..5-contains$_.DayOfWeek})[0] Montag, 22. Juni 2009 20:24:06 </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload