Created
March 28, 2014 19:04
-
-
Save angelobelchior/9840539 to your computer and use it in GitHub Desktop.
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
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