Class DateUtility
Assembly: SoCore.dll
Syntax
public static class DateUtility : Object
Methods
AddReporterHalfYears(DateTime, Int32)
Adds the required amount of half years, then subtracts a second.
Declaration
public static DateTime AddReporterHalfYears(this DateTime date, int halfYearCount = 1)
Parameters
Returns
AddReporterMonth(DateTime)
Adds a month, then subtracts a second.
Declaration
public static DateTime AddReporterMonth(this DateTime date)
Parameters
Returns
AddReporterMonths(DateTime, Int32)
Adds the required amount of months, then subtracts a second.
Declaration
public static DateTime AddReporterMonths(this DateTime date, int monthCount)
Parameters
Returns
AddReporterQuarter(DateTime)
Adds a quarter of a year, then subtracts a second.
Declaration
public static DateTime AddReporterQuarter(this DateTime date)
Parameters
Returns
AddReporterQuarters(DateTime, Int32)
Adds the required amount of quarters of a year, then subtracts a second.
Declaration
public static DateTime AddReporterQuarters(this DateTime date, int quarterCount)
Parameters
Returns
AddReporterWeek(DateTime)
Adds a week, then subtracts a second.
Declaration
public static DateTime AddReporterWeek(this DateTime date)
Parameters
Returns
AddReporterWeeks(DateTime, Int32)
Adds the required number of weeks, then subtracts a second.
Declaration
public static DateTime AddReporterWeeks(this DateTime date, int weekCount)
Parameters
Returns
AddReporterYear(DateTime)
Adds a year, then subtracts a second.
Declaration
public static DateTime AddReporterYear(this DateTime date)
Parameters
Returns
AddReporterYears(DateTime, Int32)
Adds the required amount of years, then subtracts a second.
Declaration
public static DateTime AddReporterYears(this DateTime date, int yearCount)
Parameters
Returns
CalcSeconds(DateTime)
Declaration
public static int CalcSeconds(this DateTime dt)
Parameters
Returns
CalculateEndDate(DateTime, Int32, DurationUnit)
Adds the amount of days/months depending on the DurationUnit specified.
Declaration
public static DateTime CalculateEndDate(this DateTime date, int duration, DurationUnit unit)
Parameters
Returns
CalculateEndDate(Int32, DurationUnit)
Adds the amount of days/months depending on the DurationUnit specified to the current datetime.
Declaration
public static DateTime CalculateEndDate(int duration, DurationUnit unit)
Parameters
Returns
CloseEnoughTo(DateTime, DateTime, Int32)
Declaration
public static bool CloseEnoughTo(this DateTime a, DateTime b, int toleranceSeconds = 30)
Parameters
Returns
DropFractionsOfSecond(DateTime, Nullable<DateTimeKind>)
Return a DateTime that is the same as the input parameter, but eliminate all sub-second parts by truncating them. This is how
we store datetimes in the database, and should generally be done to avoid meaningless inequalities.
Declaration
public static DateTime DropFractionsOfSecond(this DateTime input, Nullable<DateTimeKind> kind = null)
Parameters
Type |
Name |
Description |
DateTime |
input |
Input datetime
|
Nullable<DateTimeKind> |
kind |
Optional override of DateTime.Kind; the returned value will have this kind. If null or not specified then the original Kind will be propagated
|
Returns
Earliest(DateTime[])
Declaration
public static DateTime Earliest(params DateTime[] dates)
Parameters
Returns
GetFirstInMonth(DateTime)
Declaration
public static DateTime GetFirstInMonth(this DateTime date)
Parameters
Returns
GetStartOfHalfYear(DateTime)
Gets the start of the half year of the input date.
Declaration
public static DateTime GetStartOfHalfYear(this DateTime date)
Parameters
Returns
GetStartOfMonth(DateTime)
Gets the start of the month of the input date.
Declaration
public static DateTime GetStartOfMonth(this DateTime date)
Parameters
Returns
GetStartOfQuarter(DateTime)
Gets the start of the quarter that the input date is within.
Declaration
public static DateTime GetStartOfQuarter(this DateTime date)
Parameters
Returns
Type |
Description |
DateTime |
Returns a datetime representing the first second of the first day of the quarter.
|
GetStartOfWeek(DateTime, Boolean)
Gets the start of the week of the input date.
Declaration
public static DateTime GetStartOfWeek(this DateTime date, bool weekStartsOnSunday = false)
Parameters
Returns
GetStartOfYear(DateTime)
Gets the start of the year of the input date.
Declaration
public static DateTime GetStartOfYear(this DateTime date)
Parameters
Returns
GetWeekStartDelta(DateTime, Boolean)
Calculate how many days we need to go back from given date to get to the start-of-week day.
This is sunday or monday depending on preference. In .NET, dow 0 is sunday.
Declaration
public static int GetWeekStartDelta(this DateTime date, bool weekStartsOnSunday = false)
Parameters
Returns
Type |
Description |
Int32 |
Day of week delta, a negative value which when added to date will produce start of first day
|
Latest(DateTime[])
Declaration
public static DateTime Latest(params DateTime[] dates)
Parameters
Returns
Round(DateTime, Int32, RoundDirection)
Declaration
public static DateTime Round(DateTime dateTime, int minutes, RoundDirection direction)
Parameters
Returns
SetTime(DateTime, Int32, Int32, Int32, Int32)
Declaration
public static DateTime SetTime(this DateTime dt, int hour, int minute, int second = 0, int millisecond = 0)
Parameters
Returns
SetToEndOfDay(DateTime)
Copies date
and sets the time component to be 23:59:59.
Declaration
public static DateTime SetToEndOfDay(this DateTime date)
Parameters
Returns
Type |
Description |
DateTime |
A copy of date, with the time component set to 23:59:59
|
ToMinutes(Double)
Declaration
public static int ToMinutes(this double seconds)
Parameters
Type |
Name |
Description |
Double |
seconds |
|
Returns
ToMinutes(TimeSpan)
Declaration
public static int ToMinutes(this TimeSpan span)
Parameters
Returns