Skip to content

Instantly share code, notes, and snippets.

@SMoni
Created November 15, 2020 16:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SMoni/d1487b6b89707c51b260a94ab92c4c8b to your computer and use it in GitHub Desktop.
Save SMoni/d1487b6b89707c51b260a94ab92c4c8b to your computer and use it in GitHub Desktop.
function getStartOfWeek() {
begin {
$base = [DayOfWeek]::Monday
}
process {
$difference = $_.DayOfWeek - $base
$offset = (7 + $difference) % 7 * -1
$_.Date.AddDays($offset).Date
}
}
[DateTime]::Now | getStartOfWeek
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment