Created
July 6, 2012 14:05
-
-
Save jaredcacurak/3060335 to your computer and use it in GitHub Desktop.
Get the most recent DateTime extension method.
This file contains hidden or 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 DateTime GetDateOfMostRecent(this DayOfWeek dayOfWeek, DateTime date) { | |
| return date.DayOfWeek.Equals(dayOfWeek) ? date.Date : GetDateOfMostRecent(dayOfWeek, date.AddDays(-1)); | |
| } |
This file contains hidden or 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
| var lastFriday = GetDateOfMostRecent(DayOfWeek.Friday, DateTime.Now); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment