DateTime Extensions
Extensions to numeric data types such as: int, double, decimal, byte...

Tomorrow

Gets a day after given date.

                        DateTime Tomorrow(this DateTime current);Example:
                        DateTime result = DateTime.Now.Tomorrow();  
DateTime result = new DateTime(1943, 7, 23).Tomorrow(); 
                    

Yesterday

Gets a day before given date.

                        DateTime Yesterday(this DateTime current);Example:
                        DateTime result = DateTime.Now.Yesterday();  
DateTime result = new DateTime(1943, 7, 23).Yesterday(); 
                    

LastHour

Gets a day before given date.

                        DateTime LastHour(this DateTime current)Example:
                        DateTime result = DateTime.Now.LastHour();
                    

NextHour

Gets a day after given date.

                        DateTime NextHour(this DateTime current);Example:
                        DateTime result = DateTime.Now.NextHour();
                    

LastWeek

Gets a week before the given date.

                        DateTime LastWeek(this DateTime current);Example:
                        DateTime result = DateTime.Now.LastWeek();
                    

NextWeek

Gets a week after the given date.

                        DateTime NextWeek(this DateTime current);Example:
                        DateTime result = DateTime.Now.NextWeek();
                    

LastMonth

Gets a month before the given date.

                        DateTime LastMonth(this DateTime current);Example:
                        DateTime result = DateTime.Now.LastMonth();
                    

NextMonth

Gets a month after the given date.

                        DateTime NextMonth(this DateTime current);Example:
                        DateTime result = DateTime.Now.NextMonth();
                    

LastYear

Gets a year before the given date.

                        DateTime LastYear(this DateTime current);Example:
                        DateTime result = DateTime.Now.LastYear();
                    

NextYear

Gets a year after the given date.

                        DateTime NextYear(this DateTime current);Example:
                        DateTime result = DateTime.Now.NextYear();
                    

DaysAgo

Gets the number of days prior to the given date.

                        DateTime DaysAgo(this DateTime source, int days);Example:
                        DateTime result = DateTime.Now.DaysAgo(5);  
DateTime result = new DateTime(1943, 7, 23).DaysAgo(13); 
                    

DaysAfter

Gets the number of days after to the given date.

                        DateTime DaysAgo(this DateTime source, int days);Example:
                        DateTime result = DateTime.Now.DaysAfter(5);  
DateTime result = new DateTime(1943, 7, 23).DaysAfter(13); 
                    

WeeksAgo

Gets the number of weeks prior to the given date.

                        DateTime WeeksAgo(this DateTime source, int weeks);Example:
                        DateTime result = DateTime.Now.WeeksAgo(5);  
DateTime result = new DateTime(1943, 7, 23).WeeksAgo(13); 
                    

WeeksAfter

Gets the number of weeks after to the given date.

                        DateTime WeeksAfter(this DateTime source, int weeks);Example:
                        DateTime result = DateTime.Now.WeeksAfter(5);  
DateTime result = new DateTime(1943, 7, 23).WeeksAfter(13); 
                    

MonthsAgo

Gets the number of months prior to the given date.

                        DateTime MonthsAgo(this DateTime source, int months);Example:
                        DateTime result = DateTime.Now.MonthsAgo(5);  
DateTime result = new DateTime(1943, 7, 23).MonthsAgo(13); 
                    

MonthsAfter

Gets the number of months after to the given date.

                        DateTime MonthsAfter(this DateTime source, int months);Example:
                        DateTime result = DateTime.Now.MonthsAfter(5);  
DateTime result = new DateTime(1943, 7, 23).MonthsAfter(13); 
                    

YearsAgo

Gets the number of years prior to the given date.

                        DateTime YearsAgo(this DateTime source, int years);Example:
                        DateTime result = DateTime.Now.YearsAgo(5);  
DateTime result = new DateTime(1943, 7, 23).YearsAgo(13); 
                    

YearsAfter

Gets the number of years after to the given date.

                        DateTime YearsAfter(this DateTime source, int years);Example:
                        DateTime result = DateTime.Now.YearsAfter(5);  
DateTime result = new DateTime(1943, 7, 23).YearsAfter(13); 
                    

FirstDayOfMonth

Gets the first day of month.

                        DateTime FirstDayOfMonth(this DateTime date);Example:
                        DateTime result = DateTime.Now.FirstDayOfMonth();  
DateTime result = new DateTime(1943, 7, 23).FirstDayOfMonth(); 
                    

LastDayOfMonth

Gets the last day of month.

                        DateTime LastDayOfMonth(this DateTime date);Example:
                        DateTime result = DateTime.Now.LastDayOfMonth();  
DateTime result = new DateTime(1943, 7, 23).LastDayOfMonth(); 
                    

DaysLeft

Gets the number of days left to the target date.

                        double DaysLeft(this DateTime source, DateTime target);Example:
                        DateTime date = new DateTime(2021, 9, 20);  
DateTime result = DateTime.Now.DaysLeft(date); 
                    

DaysInMonth

Gets the number of the days of the given date month.

                        int DaysInMonth(this DateTime date);Example:
                        DateTime date = new DateTime(2021, 9, 20);  
int result = date.DaysInMonth(date); 
                    

IsBetween

Determines whether the given date is between the two given dates.

                        bool IsBetween(this DateTime dateToCompare, DateTime startDate, DateTime endDate);Example:
                        DateTime date = new DateTime(2021, 8, 20);  
DateTime date2 = new DateTime(2021, 9, 20);
bool result = DateTime.Now.IsBetween(date, date2); 
                    

IsBefore

Determines whether the given date is before the target one.

                        bool IsBefore(this DateTime dateToCompare, DateTime target);Example:
                        DateTime date = new DateTime(2021, 9, 20);  
bool result = DateTime.Now.IsBefore(date); 
                    

IsAfter

Determines whether the given date is after the target one.

                        bool IsAfter(this DateTime dateToCompare, DateTime target);Example:
                        DateTime date = new DateTime(2021, 8, 20);  
bool result = DateTime.Now.IsAfter(date); 
                    

IsYearLeap

Determines whether the given year is a leap year.

                        bool IsYearLeap(this DateTime year);Example:
                        DateTime date = new DateTime(2021, 8, 20);
bool result = date.IsYearLeap(); // false
                    

PreviousLeapYear

Gets the previous leap year based on the given year.

                        DateTime PreviousLeapYear(this DateTime year);Example:
                        DateTime date = new DateTime(2021, 9, 20);
DateTime result = date.PreviousLeapYear(); 
                    

NextLeapYear

Gets the next leap year based on the given year.

                        DateTime NextLeapYear(this DateTime year);Example:
                        DateTime date = new DateTime(2021, 9, 20);
DateTime result = date.NextLeapYear(); // 2024 
                    

GetAge

Calculates age based on given date.

                        DateTime GetAge(this DateTime year);Example:
                        DateTime date = new DateTime(1954, 9, 20);
int result = date.GetAge(); // 67 (According to the current date "2021, September, 1")
                    

DayName

Gets the name of the given date time.

                        DateTime DayName(this DateTime year);Example:
                        string result = DateTime.Now.DayName();