Last active
December 21, 2015 10:48
-
-
Save jeremykdev/6294362 to your computer and use it in GitHub Desktop.
Collection of extension methods for working DateTime value in .NET.
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 DateTimeExtensionMethods | |
{ | |
//get first day of month for a given date | |
public static DateTime FirstDayOfMonth(this DateTime input) | |
{ | |
return new DateTime(input.Year, input.Month, 1); | |
} | |
//get last day of month for a given date | |
public static DateTime LastDayOfMonth(this DateTime input) | |
{ | |
//get first day of NEXT month, subtract one day | |
return input.AddMonths(1).FirstDayOfMonth().AddDays(-1); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment