Created
January 8, 2019 10:37
-
-
Save SamKr/1c5498e4d44b6ea7991b885eca3aca88 to your computer and use it in GitHub Desktop.
Get first monday of given year/month
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
internal static DateTime GetFirstMonday(int month, int year) | |
{ | |
var dt = new DateTime(year, month, 1, 12, 00, 00); | |
for (var i = 0; i < 7; i++) | |
{ | |
if (dt.DayOfWeek == DayOfWeek.Monday) | |
{ | |
return dt; | |
} | |
dt = dt.AddDays(1); | |
} | |
Console.WriteLine($"Unable to find 1st monday for year '{year}' and month '{month}'!"); | |
return DateTime.MinValue; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment