Created
July 11, 2012 15:36
-
-
Save JayDouglass/3091202 to your computer and use it in GitHub Desktop.
Start of week and end of week
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace Extensions | |
{ | |
public static class DateTimeExtensions | |
{ | |
public static DateTime StartOfWeek(DateTime value) | |
{ | |
var startOfWeek_ = DayOfWeek.Sunday; | |
var delta = value.DayOfWeek - startOfWeek_; | |
if (delta < 0) | |
delta += 7; | |
return value.AddDays(-delta).Date; | |
} | |
public static DateTime EndOfWeek(DateTime value) | |
{ | |
var endOfWeek_ = DayOfWeek.Saturday; | |
var delta = endOfWeek_ - value.DayOfWeek; | |
if (delta < 0) | |
delta += 7; | |
return value.AddDays(delta).Date; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment