Introduction
While working in different projects, I encountered frustrating problems related to date and time programming. So I wrote a few classes that helped me tackle those problems.
The code
Here is my static helper class:
public static DayOfWeek GetLastDayOfWeek(CultureInfo culture)
public static DateTime GetFirstDateOfWeek(DateTime dateTime, CultureInfo culture)
public static DateTime GetLastDateOfWeek(DateTime dateTime, CultureInfo culture)
public static DateTime GetLastDateOfMonth(int year, int month)
public static DateTime GetLastDateOfYear(int year)
public static int GetWeeksInYear(int year, CultureInfo culture)
public static int GetRemainingDaysInWeek(DateTime dateTime, CultureInfo culture)
public static int GetWeekNumber(DateTime dateTime, CultureInfo culture)
public static bool AreTimePeriodsIntersecting(TimePeriod tp1, TimePeriod tp2)
public static bool IsDateInPeriod(DateTime dateTime, TimePeriod timePeriod)
The TimeDifference
class receives a start date and an end date, and returns the difference in Years, Months, Weeks, Days, Hours, Minutes, Seconds, and Miliseconds between them in two modes.
Let's take, for example, two dates: 06/26/2009 and 05/02/2013.
- First difference mode (time-units independence): 4 years, or (more accurately) 47 months, or (more accurately) 200 weeks, or (more accurately) 1406 days.
- Second difference mode (time-units dependence): 3 years and 10 months and 6 days.
Hope it will be of great help to someone, and please report any errors or suggestions.
NB: TimeZone and Daylight Savings Time are not taken into account.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.