Created
January 13, 2014 18:52
-
-
Save jahanson/8405855 to your computer and use it in GitHub Desktop.
Get the first day of the week. ex.
DateTime dt = DateTime.Now.StartOfWeek(DayOfWeek.Monday);
DateTime dt = DateTime.Now.StartOfWeek(DayOfWeek.Sunday); Credit to http://stackoverflow.com/a/38064/1467924
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
public static class DateTimeExtensions | |
{ | |
public static DateTime StartOfWeek(this DateTime dt, DayOfWeek startOfWeek) | |
{ | |
int diff = dt.DayOfWeek - startOfWeek; | |
if (diff < 0) | |
{ | |
diff += 7; | |
} | |
return dt.AddDays(-1 * diff).Date; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment