Skip to content

Instantly share code, notes, and snippets.

@angelobelchior
Created March 28, 2014 19:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save angelobelchior/9840539 to your computer and use it in GitHub Desktop.
Save angelobelchior/9840539 to your computer and use it in GitHub Desktop.
namespace System
{
public static class DateTimeExtentions
{
public static bool IsWeekend(this DateTime self)
{
return (self.DayOfWeek == DayOfWeek.Sunday || self.DayOfWeek == DayOfWeek.Saturday);
}
public static bool IsLeapYear(this DateTime self)
{
return DateTime.DaysInMonth(self.Year, 2) == 29;
}
public static int Age(this DateTime self)
{
return Age(self, DateTime.Today);
}
public static int Age(this DateTime self, DateTime laterDate)
{
int age;
age = laterDate.Year - self.Year;
if (age > 0)
age -= Convert.ToInt32(laterDate.Date < self.Date.AddYears(age));
else
age = 0;
return age;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment