Skip to content

Instantly share code, notes, and snippets.

@rdbartram
Created July 28, 2017 11:38
Show Gist options
  • Save rdbartram/957cd3a5340709ea8f4cc0b722748f8e to your computer and use it in GitHub Desktop.
Save rdbartram/957cd3a5340709ea8f4cc0b722748f8e to your computer and use it in GitHub Desktop.
Get workday x days ago
function Get-PreviousWorkday ($Days = 0) {
begin {
$date = get-date
}
process {
$i = 0
do {
$date = $date.adddays(-1)
if ($date.DayOfWeek -match '^[^s]') {
$i++
}
} while ($i -lt $days)
}
end {
return $date.Date
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment