Skip to content

DateTimeExtensions Class ​

Definition ​

Extensions for the DateTime datatype

  • Namespace: JASE.Extensions
  • Assembly: JASE.Primitives.dll

Methods ​

NameDescription
DateTime BeginningOfMonth(DateTime dt)Returns 1st day of the Month for the specified date
DateTime BeginningOfQuarter(DateTime dt)Returns 1st day of the Quarter for the specified date
DateTime BeginningOfYear(DateTime dt)Returns last day of the Year for the specified date
int BusinessDaysBetween(DateTime input, DateTime end, IEnumerable<DateTime> holidays, IEnumerable<DayOfWeek> excludeDays = null, bool allowDateFlip = null)Calculate Business Days between 2 dates accounting for defined holidays and excluding specified days of the week If allowReverse is true, the method reverses input and end when input > end.
int BusinessDaysBetween(DateTime input, DateTime end, IEnumerable<DateTime> holidays, bool excludeWeekends, CultureInfo culture = null)Calculate Business Days between 2 dates accounting for defined holidays
int CountDoWBetween(DateTime input, DateTime end, DayOfWeek dow, IEnumerable<DateTime> holidays = null, bool allowDateFlip = null)Counts the occurences of DayOfWeek between two days accounting for holidays If allowReverse is true, the method reverses input and end when input > end.
DateTime DOW(DateTime dt, DayOfWeek dow)Returns Date of the relative next day of the week
int DOWBetween(DateTime dt, DateTime end, DayOfWeek dow, bool allowDateFlip = null)Returns Date of the relative next day of the week If allowDateFlip is true and end precedes start, the dates will be reversed.
DateTime EndOfMonth(DateTime dt)Returns last day of the Month for the specified date
DateTime EndOfQuarter(DateTime dt)Returns last day of the Quarter for the specified date
DateTime EndOfWeek(DateTime dt, CultureInfo culture = null)Returns last day of the Week for the specified date accounting for Culture
DateTime EndOfYear(DateTime dt)Returns last day of the Year for the specified date
bool IsFirst(DateTime dt, DayOfWeek dow)Checks if specified Date is the first occurrence of DayofWeek in the month
bool IsLast(DateTime dt, DayOfWeek dow)Checks if specified Date is the last occurrence of DayofWeek in the month
bool IsSameMonth(DateTime dt, DateTime asDate)Checks if two dates are in the same month
bool IsWeekday(DateTime dt, CultureInfo culture = null)Checks if date is a normal work Week day based on the Culture
bool IsWeekend(DateTime dt, CultureInfo culture = null)Checks if date is a Weekend based on the Culture
DateTime LastDOW(DateTime dt, DayOfWeek dow)Returns Date of the relative previous day of the week
int MinutesPastMidnight(DateTime input, int minutes)Calculates the number of minutes past midnight for a specified DateTime
DateTime MinutesPastMidnightAsDT(DateTime input, int minutes)Calculates the number of minutes past midnight for a specified DateTime
DateTime NextDOW(DateTime dt, DayOfWeek dow, int loop = null)Returns the DateTime for the next occurence of the Day of Week
DateTime NextMonth(DateTime dt)Returns DateTime object representing the 1st day of the following month
DateTime NextQuarter(DateTime dt)Returns DateTime representing the 1st day of the next quarter
DateTime NextWeek(DateTime dt, CultureInfo culture = null)Returns DateTime representing the 1st day of the next week
DateTime NextYear(DateTime dt)Returns DateTime representing the 1st day of the next year
int RelativeHours(DateTime input, int hours, int minimum = null)Returns a delay in milliseconds until the specified number of hours from the input DateTime. If the time has already passed, returns the provided minimum.
int RelativeMinutes(DateTime input, int minutes, int minimum = null)Returns a delay in milliseconds until the specified number of minutes from the input DateTime. If the time has already passed, returns the provided minimum.
int RelativeSeconds(DateTime input, int seconds, int minimum = null)Returns a delay in milliseconds until the specified number of seconds from the input DateTime. If the time has already passed, returns the provided minimum.
DateTime StartOfWeek(DateTime dt, CultureInfo culture = null)Returns DateTime representing the start of the current week
DateTime ThisMonth(DateTime dt)Returns DateTime representing the start of the current month
string ToISO8601(DateTime input, int precision = null)Returns input DateTime formatted as yyyy-MM-ddTHH:mm:ss.K
string ToISO8601(DateTime? input)Overload for nullable DateTime variable
DateTime ToISO8601Date(DateTime input)Returns a new DateTime with the same year, month, day, hour, minute, and second as the input, preserving the kind. Useful for stripping sub-second precision or millisecond noise.
string ToLdapFormat(DateTime input)Returns input DateTime formatted as yyyyMMddHHmmss.0Z
DateTime TopOfTheHour(DateTime input)Returns DateTime representing the beginning of the next hour
string ToRFC3339(DateTime input)Returns input DateTime formatted for RFC3339 compliance
DateTime ToTimezone(DateTime date, TimeZoneInfo timezone, TimeZoneInfo sourceTimezone)Converts input DateTime to the destination timezone
long ToUnixEpoch(DateTime date)Returns the # of seconds since UNIX Epoch
DateTime ToUtcKind(DateTime date)Converts a DateTime Kind to UTC
string ToWcfDateString(DateTime date)Returns the time-stamp formatted for Windows Communication Foundation i.e /Date(<number of ticks since Jan 1, 1970>)/
int WeeksBetween(DateTime start, DateTime end)Calculate weeks between two dates