Skip to content

Instantly share code, notes, and snippets.

@jeremykdev
Last active December 21, 2015 10:48
Show Gist options
  • Save jeremykdev/6294362 to your computer and use it in GitHub Desktop.
Save jeremykdev/6294362 to your computer and use it in GitHub Desktop.
Collection of extension methods for working DateTime value in .NET.
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