Class DateTimeEx
Class containing some extension methods for System.DateTime.
Inheritance
Inherited Members
Namespace:Extend
Assembly:Extend.dll
Syntax
public static class DateTimeEx
Methods
| Improve this Doc View SourceAge(DateTime, Nullable<DateTime>)
Calculates the difference between the year of the current and the given date time.
Declaration
public static int Age(this DateTime dateTime, DateTime? now = null)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | The date time value. |
System.Nullable<T><System.DateTime> | now | The 'current' date used to calculate the age, or null to use System.DateTime.Now. |
Returns
Type | Description |
---|---|
System.Int32 | The difference between the year of the current and the given date time. |
Remarks
now can be smaller than dateTime, which results in negative results. Source from: http://stackoverflow.com/questions/9/how-do-i-calculate-someones-age-in-c
Elapsed(DateTime)
Calculates the elapsed time between the given date time value and DateTime.Now.
Declaration
public static TimeSpan Elapsed(this DateTime dateTime)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | The date time value. |
Returns
Type | Description |
---|---|
System.TimeSpan | Returns the elapsed time between the given date time value and DateTime.Now. |
EndOfDay(DateTime)
Returns the last moment of the day ("23:59:59:999") represented by the given date time value.
Declaration
public static DateTime EndOfDay(this DateTime day)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | day | The day to get the end of. |
Returns
Type | Description |
---|---|
System.DateTime | Returns the last moment of the day ("23:59:59:999") represented by the given date time value. |
EndOfMonth(DateTime)
Returns the last moment ("23:59:59:999") of the month represented by the given date time value.
Declaration
public static DateTime EndOfMonth(this DateTime month)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | month | The @this to act on. |
Returns
Type | Description |
---|---|
System.DateTime | Returns the last moment ("23:59:59:999") of the month represented by the given date time value. |
EndOfWeek(DateTime, DayOfWeek)
Returns the last day of the current week. Note: This method uses the given day as last day of the week. Default is Sunday.
Declaration
public static DateTime EndOfWeek(this DateTime week, DayOfWeek lastDayOfWeek = DayOfWeek.Sunday)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | week | The week to return the end of. |
System.DayOfWeek | lastDayOfWeek | The last day of the week. Default is Sunday. |
Returns
Type | Description |
---|---|
System.DateTime | Returns the last day of the current week. |
EndOfYear(DateTime)
Returns the last moment ("23:59:59:999") of the year represented by the given date time.
Declaration
public static DateTime EndOfYear(this DateTime year)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | year | The year to return the end of. |
Returns
Type | Description |
---|---|
System.DateTime | Returns the last moment ("23:59:59:999") of the year represented by the given date time. |
FirstDayOfWeek(DateTime)
Returns the first day of the week, represented by the given date time.
Declaration
public static DateTime FirstDayOfWeek(this DateTime week)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | week | The week to return the first day of. |
Returns
Type | Description |
---|---|
System.DateTime | Returns the first day of the week, represented by the given date time. |
GetWeekOfYear(DateTime)
Gets the week-number of the given date-time value.
Declaration
public static int GetWeekOfYear(this DateTime dateTime)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | The date-time value. |
Returns
Type | Description |
---|---|
System.Int32 | Returns the number of the given week. |
Remarks
This implementation is ISO 8601 compatible see: https://en.wikipedia.org/wiki/ISO_8601. For .Net details see: http://stackoverflow.com/questions/11154673/get-the-correct-week-number-of-a-given-date This presumes that weeks start with Monday. Week 1 is the 1st week of the year with a Thursday in it.
Intersects(DateTime, DateTime, DateTime, DateTime)
Checks if the two date ranges intersects.
Declaration
public static bool Intersects(this DateTime startDate, DateTime endDate, DateTime intersectingStartDate, DateTime intersectingEndDate)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | startDate | The start date. |
System.DateTime | endDate | The end date. |
System.DateTime | intersectingStartDate | The intersecting start date. |
System.DateTime | intersectingEndDate | The intersecting end date. |
Returns
Type | Description |
---|---|
System.Boolean | Returns true if the two date ranges intersects, otherwise false. |
IsAfternoon(DateTime)
Checks whether the given date time value is at afternoon or not.
Declaration
public static bool IsAfternoon(this DateTime dateTime)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | The date time to check. |
Returns
Type | Description |
---|---|
System.Boolean | Returns true if the date time value is at afternoon, otherwise false. |
IsFuture(DateTime)
Checks if the date time value is in the future.
Declaration
public static bool IsFuture(this DateTime dateTime)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | The @date time to check. |
Returns
Type | Description |
---|---|
System.Boolean | Returns true if the value is in the future, otherwise false. |
IsLastDayOfMonth(DateTime)
Gets a value indicating whether the given date-time value is the last day of the month represented in dateTime.
Declaration
public static bool IsLastDayOfMonth(this DateTime dateTime)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | The date-time value. |
Returns
Type | Description |
---|---|
System.Boolean | Returns a value of true if the given date-time value is the last day of the month. |
IsMorning(DateTime)
Checks is the date time value is morning.
Declaration
public static bool IsMorning(this DateTime dateTime)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | The date time to check. |
Returns
Type | Description |
---|---|
System.Boolean | Returns true if the date time is morning, otherwise false. |
IsPast(DateTime)
Checks if the date time value is in the past.
Declaration
public static bool IsPast(this DateTime dateTime)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | The date time to check. |
Returns
Type | Description |
---|---|
System.Boolean | Returns true if the value is in the past, otherwise false. |
IsSameDay(DateTime, DateTime)
Gets whether the given date-time values are the same day.
Declaration
public static bool IsSameDay(this DateTime dateTime, DateTime otherDateTime)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | The first date-time value. |
System.DateTime | otherDateTime | The second date-time value. |
Returns
Type | Description |
---|---|
System.Boolean | Returns true if the given date-time values are the same day, otherwise false. |
IsSameMonthAndYear(DateTime, DateTime)
Gets whether the given date-time values are the same month and year.
Declaration
public static bool IsSameMonthAndYear(this DateTime dateTime, DateTime otherDateTime)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | The first date-time value. |
System.DateTime | otherDateTime | The second date-time value. |
Returns
Type | Description |
---|---|
System.Boolean | Returns true if the given date-time values are the same month and year, otherwise false. |
IsTimeEquals(DateTime, DateTime)
Checks if the time is equals to the given time.
Declaration
public static bool IsTimeEquals(this DateTime time, DateTime timeToCompare)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | time | The time to check. |
System.DateTime | timeToCompare | The time to compare. |
Returns
Type | Description |
---|---|
System.Boolean | Returns true if the time is equals, otherwise false. |
IsToday(DateTime)
Checks if the given date time is today.
Declaration
public static bool IsToday(this DateTime dateTime)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | The date time to check. |
Returns
Type | Description |
---|---|
System.Boolean | Returns true if the date time value is today, otherwise false. |
IsWeekdDay(DateTime)
Checks if the given day is a week day (MOnday - Friday).
Declaration
public static bool IsWeekdDay(this DateTime day)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | day | The day to check. |
Returns
Type | Description |
---|---|
System.Boolean | Returns true if the day is a week day, otherwise false. |
IsWeekendDay(DateTime)
Checks if the given day is a weekend day (Saturday or Sunday).
Declaration
public static bool IsWeekendDay(this DateTime day)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | day | The day to check. |
Returns
Type | Description |
---|---|
System.Boolean | Returns true if the day is a weekend day, otherwise false. |
LastDayOfWeek(DateTime)
Returns the last day of the given week.
Declaration
public static DateTime LastDayOfWeek(this DateTime week)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | week | The week to get the last day of. |
Returns
Type | Description |
---|---|
System.DateTime | Returns the last day of the given week. |
NextMonthStart(DateTime)
Returns the first day of the next month, based on the given date-time value.
Declaration
public static DateTime NextMonthStart(this DateTime dateTime)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | The date-time value. |
Returns
Type | Description |
---|---|
System.DateTime | Returns the first day of the next month, based on the given date-time value. |
NextWeekDay(DateTime)
Gets the next week day, based on the given day.
Declaration
public static DateTime NextWeekDay(this DateTime day)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | day | The day. |
Returns
Type | Description |
---|---|
System.DateTime | Returns the next week day (can be day if the given day is a week day). |
StartOfDay(DateTime)
Returns the start of the given day ("00:00:00:000").
Declaration
public static DateTime StartOfDay(this DateTime day)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | day | The day to get the start of. |
Returns
Type | Description |
---|---|
System.DateTime | Returns the start of the given day ("00:00:00:000"). |
StartOfMonth(DateTime)
Returns the start of the given month (with time set to "00:00:00:000").
Declaration
public static DateTime StartOfMonth(this DateTime month)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | month | The month to get the start of. |
Returns
Type | Description |
---|---|
System.DateTime | Returns the start of the given month (with time set to "00:00:00:000"). |
StartOfWeek(DateTime, DayOfWeek)
Returns the first day of the current week. Note: This method uses the given day as first day of the week. Default is Monday.
Declaration
public static DateTime StartOfWeek(this DateTime week, DayOfWeek firstDayOfWeek = DayOfWeek.Monday)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | week | The week to return the start of. |
System.DayOfWeek | firstDayOfWeek | The first day of the week. Default is Monday. |
Returns
Type | Description |
---|---|
System.DateTime | Returns the first day of the current week. |
StartOfYear(DateTime)
Returns the start of the given year with time set to "00:00:00:000".
Declaration
public static DateTime StartOfYear(this DateTime year)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | year | The year to get the start of. |
Returns
Type | Description |
---|---|
System.DateTime | Returns the start of the given year with time set to "00:00:00:000". |
ToFullDateTimeString(DateTime)
Converts the DateTime value to a full date time string.
Declaration
public static string ToFullDateTimeString(this DateTime dateTime)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | The DateTime value to convert. |
Returns
Type | Description |
---|---|
System.String | The given value converted to a full date time string. |
ToFullDateTimeString(DateTime, CultureInfo)
Converts the DateTime value to a full date time string.
Declaration
public static string ToFullDateTimeString(this DateTime dateTime, CultureInfo culture)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | The DateTime value to convert. |
System.Globalization.CultureInfo | culture | The culture. |
Returns
Type | Description |
---|---|
System.String | The given value converted to a full date time string. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | The culture can not be null. |
ToFullDateTimeString(DateTime, DateTimeFormatInfo)
Converts the DateTime value to a full date time string.
Declaration
public static string ToFullDateTimeString(this DateTime dateTime, DateTimeFormatInfo formatInfo)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | The DateTime value to convert. |
System.Globalization.DateTimeFormatInfo | formatInfo | The date time format info. |
Returns
Type | Description |
---|---|
System.String | The given value converted to a full date time string. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | The format info can not be null. |
ToLongDateShortTimeString(DateTime)
Converts the DateTime value to a long date short time string.
Declaration
public static string ToLongDateShortTimeString(this DateTime dateTime)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | The DateTime value to convert. |
Returns
Type | Description |
---|---|
System.String | The given value converted to a long date short time string. |
ToLongDateShortTimeString(DateTime, CultureInfo)
Converts the DateTime value to a long date short time string.
Declaration
public static string ToLongDateShortTimeString(this DateTime dateTime, CultureInfo culture)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | The DateTime value to convert. |
System.Globalization.CultureInfo | culture | The culture. |
Returns
Type | Description |
---|---|
System.String | The given value converted to a long date short time string. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | The culture can not be null. |
ToLongDateShortTimeString(DateTime, DateTimeFormatInfo)
Converts the DateTime value to a long date short time string.
Declaration
public static string ToLongDateShortTimeString(this DateTime dateTime, DateTimeFormatInfo formatInfo)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | The DateTime value to convert. |
System.Globalization.DateTimeFormatInfo | formatInfo | The date time format info. |
Returns
Type | Description |
---|---|
System.String | The given value converted to a long date short time string. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | The format info can not be null. |
ToLongDateString(DateTime)
Converts the DateTime value to a long date time string.
Declaration
public static string ToLongDateString(this DateTime dateTime)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | The DateTime value to convert. |
Returns
Type | Description |
---|---|
System.String | The given value converted to a long date time string. |
ToLongDateString(DateTime, CultureInfo)
Converts the DateTime value to a long date time string.
Declaration
public static string ToLongDateString(this DateTime dateTime, CultureInfo culture)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | The DateTime value to convert. |
System.Globalization.CultureInfo | culture | The culture. |
Returns
Type | Description |
---|---|
System.String | The given value converted to a long date time string. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | The culture can not be null. |
ToLongDateString(DateTime, DateTimeFormatInfo)
Converts the DateTime value to a long date time string.
Declaration
public static string ToLongDateString(this DateTime dateTime, DateTimeFormatInfo formatInfo)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | The DateTime value to convert. |
System.Globalization.DateTimeFormatInfo | formatInfo | The date time format info. |
Returns
Type | Description |
---|---|
System.String | The given value converted to a long date time string. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | The format info can not be null. |
ToLongTimeString(DateTime)
Converts the DateTime value to a long time string.
Declaration
public static string ToLongTimeString(this DateTime dateTime)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | The DateTime value to convert. |
Returns
Type | Description |
---|---|
System.String | The given value converted to a long time string. |
ToLongTimeString(DateTime, CultureInfo)
Converts the DateTime value to a long time string.
Declaration
public static string ToLongTimeString(this DateTime dateTime, CultureInfo culture)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | The DateTime value to convert. |
System.Globalization.CultureInfo | culture | The culture. |
Returns
Type | Description |
---|---|
System.String | The given value converted to a long time string. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | The culture can not be null. |
ToLongTimeString(DateTime, DateTimeFormatInfo)
Converts the DateTime value to a long time string.
Declaration
public static string ToLongTimeString(this DateTime dateTime, DateTimeFormatInfo formatInfo)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | The DateTime value to convert. |
System.Globalization.DateTimeFormatInfo | formatInfo | The date time format info. |
Returns
Type | Description |
---|---|
System.String | The given value converted to a long time string. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | The format info can not be null. |
ToMonthDayString(DateTime)
Converts the DateTime value to a month day string.
Declaration
public static string ToMonthDayString(this DateTime dateTime)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | The DateTime value to convert. |
Returns
Type | Description |
---|---|
System.String | The given value converted to a month day string. |
ToMonthDayString(DateTime, CultureInfo)
Converts the DateTime value to a month day string.
Declaration
public static string ToMonthDayString(this DateTime dateTime, CultureInfo culture)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | The DateTime value to convert. |
System.Globalization.CultureInfo | culture | The culture. |
Returns
Type | Description |
---|---|
System.String | The given value converted to a month day string. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | The culture can not be null. |
ToMonthDayString(DateTime, DateTimeFormatInfo)
Converts the DateTime value to a month day string.
Declaration
public static string ToMonthDayString(this DateTime dateTime, DateTimeFormatInfo formatInfo)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | The DateTime value to convert. |
System.Globalization.DateTimeFormatInfo | formatInfo | The date time format info. |
Returns
Type | Description |
---|---|
System.String | The given value converted to a month day string. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | The format info can not be null. |
ToMonthString(DateTime)
Converts the DateTime value to a month string.
Declaration
public static string ToMonthString(this DateTime dateTime)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | The DateTime value to convert. |
Returns
Type | Description |
---|---|
System.String | The given value converted to a year month string. |
ToMonthString(DateTime, CultureInfo)
Converts the DateTime value to a month string.
Declaration
public static string ToMonthString(this DateTime dateTime, CultureInfo culture)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | The DateTime value to convert. |
System.Globalization.CultureInfo | culture | The culture. |
Returns
Type | Description |
---|---|
System.String | The given value converted to a year month string. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | The culture can not be null. |
ToMonthString(DateTime, DateTimeFormatInfo)
Converts the DateTime value to a month string.
Declaration
public static string ToMonthString(this DateTime dateTime, DateTimeFormatInfo formatInfo)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | The DateTime value to convert. |
System.Globalization.DateTimeFormatInfo | formatInfo | The date time format info. |
Returns
Type | Description |
---|---|
System.String | The given value converted to year month string. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | The format info can not be null. |
Tomorrow(DateTime)
Adds a day to the given date time value.
Declaration
public static DateTime Tomorrow(this DateTime dateTime)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | The date time to increase. |
Returns
Type | Description |
---|---|
System.DateTime | Tomorrow date at same time. |
ToShortDateLongTimeString(DateTime)
Converts the DateTime value to a short date long time string.
Declaration
public static string ToShortDateLongTimeString(this DateTime dateTime)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | The DateTime value to convert. |
Returns
Type | Description |
---|---|
System.String | The given value converted to a short date long time string. |
ToShortDateLongTimeString(DateTime, CultureInfo)
Converts the DateTime value to a short date long time string.
Declaration
public static string ToShortDateLongTimeString(this DateTime dateTime, CultureInfo culture)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | The DateTime value to convert. |
System.Globalization.CultureInfo | culture | The culture. |
Returns
Type | Description |
---|---|
System.String | The given value converted to a short date long time string. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | The culture can not be null. |
ToShortDateLongTimeString(DateTime, DateTimeFormatInfo)
Converts the DateTime value to a short date long time string.
Declaration
public static string ToShortDateLongTimeString(this DateTime dateTime, DateTimeFormatInfo formatInfo)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | The DateTime value to convert. |
System.Globalization.DateTimeFormatInfo | formatInfo | The date time format info. |
Returns
Type | Description |
---|---|
System.String | The given value converted to a short date long time string. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | The format info can not be null. |
ToShortDateString(DateTime)
Converts the DateTime value to a short date string.
Declaration
public static string ToShortDateString(this DateTime dateTime)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | The DateTime value to convert. |
Returns
Type | Description |
---|---|
System.String | The given value converted to a short date string. |
ToShortDateString(DateTime, CultureInfo)
Converts the DateTime value to a short date string.
Declaration
public static string ToShortDateString(this DateTime dateTime, CultureInfo culture)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | The DateTime value to convert. |
System.Globalization.CultureInfo | culture | The culture. |
Returns
Type | Description |
---|---|
System.String | The given value converted to a short date string. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | The culture can not be null. |
ToShortDateString(DateTime, DateTimeFormatInfo)
Converts the DateTime value to a short date string.
Declaration
public static string ToShortDateString(this DateTime dateTime, DateTimeFormatInfo formatInfo)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | The DateTime value to convert. |
System.Globalization.DateTimeFormatInfo | formatInfo | The date time format info. |
Returns
Type | Description |
---|---|
System.String | The given value converted to a short date string. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | The format info can not be null. |
ToShortDateTimeString(DateTime)
Converts the DateTime value to a short date time string.
Declaration
public static string ToShortDateTimeString(this DateTime dateTime)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | The DateTime value to convert. |
Returns
Type | Description |
---|---|
System.String | The given value converted to a short date time string. |
ToShortDateTimeString(DateTime, CultureInfo)
Converts the DateTime value to a short date time string.
Declaration
public static string ToShortDateTimeString(this DateTime dateTime, CultureInfo culture)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | The DateTime value to convert. |
System.Globalization.CultureInfo | culture | The culture. |
Returns
Type | Description |
---|---|
System.String | The given value converted to a short date time string. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | The culture can not be null. |
ToShortDateTimeString(DateTime, DateTimeFormatInfo)
Converts the DateTime value to a short date time string.
Declaration
public static string ToShortDateTimeString(this DateTime dateTime, DateTimeFormatInfo formatInfo)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | The DateTime value to convert. |
System.Globalization.DateTimeFormatInfo | formatInfo | The date time format info. |
Returns
Type | Description |
---|---|
System.String | The given value converted to a short date time string. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | The format info can not be null. |
ToShortTimeString(DateTime)
Converts the DateTime value to a short time string.
Declaration
public static string ToShortTimeString(this DateTime dateTime)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | The DateTime value to convert. |
Returns
Type | Description |
---|---|
System.String | The given value converted to a short time string. |
ToShortTimeString(DateTime, CultureInfo)
Converts the DateTime value to a short time string.
Declaration
public static string ToShortTimeString(this DateTime dateTime, CultureInfo culture)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | The DateTime value to convert. |
System.Globalization.CultureInfo | culture | The culture. |
Returns
Type | Description |
---|---|
System.String | The given value converted to a short time string. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | The culture can not be null. |
ToShortTimeString(DateTime, DateTimeFormatInfo)
Converts the DateTime value to a short time string.
Declaration
public static string ToShortTimeString(this DateTime dateTime, DateTimeFormatInfo formatInfo)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | The DateTime value to convert. |
System.Globalization.DateTimeFormatInfo | formatInfo | The date time format info. |
Returns
Type | Description |
---|---|
System.String | The given value converted to a short time string. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | The format info can not be null. |
ToSortableDateTimeString(DateTime)
Converts the DateTime value to a sortable date time string.
Declaration
public static string ToSortableDateTimeString(this DateTime dateTime)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | The DateTime value to convert. |
Returns
Type | Description |
---|---|
System.String | The given value converted to a sortable date time string. |
ToSortableDateTimeString(DateTime, CultureInfo)
Converts the DateTime value to a sortable date time string.
Declaration
public static string ToSortableDateTimeString(this DateTime dateTime, CultureInfo culture)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | The DateTime value to convert. |
System.Globalization.CultureInfo | culture | The culture. |
Returns
Type | Description |
---|---|
System.String | The given value converted to a sortable date time string. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | The culture can not be null. |
ToSortableDateTimeString(DateTime, DateTimeFormatInfo)
Converts the DateTime value to a sortable date time string.
Declaration
public static string ToSortableDateTimeString(this DateTime dateTime, DateTimeFormatInfo formatInfo)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | The DateTime value to convert. |
System.Globalization.DateTimeFormatInfo | formatInfo | The date time format info. |
Returns
Type | Description |
---|---|
System.String | The given value converted to a sortable date time string. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | The format info can not be null. |
ToUniversalSortableDateTimeString(DateTime)
Converts the DateTime value to a universal sortable date time string.
Declaration
public static string ToUniversalSortableDateTimeString(this DateTime dateTime)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | The DateTime value to convert. |
Returns
Type | Description |
---|---|
System.String | The given value converted to a universal sortable date time string. |
ToUniversalSortableDateTimeString(DateTime, CultureInfo)
Converts the DateTime value to a universal sortable date time string.
Declaration
public static string ToUniversalSortableDateTimeString(this DateTime dateTime, CultureInfo culture)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | The DateTime value to convert. |
System.Globalization.CultureInfo | culture | The culture. |
Returns
Type | Description |
---|---|
System.String | The given value converted to a universal sortable date time string. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | The culture can not be null. |
ToUniversalSortableDateTimeString(DateTime, DateTimeFormatInfo)
Converts the DateTime value to a universal sortable date time string.
Declaration
public static string ToUniversalSortableDateTimeString(this DateTime dateTime, DateTimeFormatInfo formatInfo)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | The DateTime value to convert. |
System.Globalization.DateTimeFormatInfo | formatInfo | The date time format info. |
Returns
Type | Description |
---|---|
System.String | The given value converted to a universal sortable date time string. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | The format info can not be null. |
ToUniversalSortableLongDateTimeString(DateTime)
Converts the DateTime value to a universal sortable long date time string.
Declaration
public static string ToUniversalSortableLongDateTimeString(this DateTime dateTime)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | The DateTime value to convert. |
Returns
Type | Description |
---|---|
System.String | The given value converted to a universal sortable long date time string. |
ToUniversalSortableLongDateTimeString(DateTime, CultureInfo)
Converts the DateTime value to a universal sortable long date time string.
Declaration
public static string ToUniversalSortableLongDateTimeString(this DateTime dateTime, CultureInfo culture)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | The DateTime value to convert. |
System.Globalization.CultureInfo | culture | The culture. |
Returns
Type | Description |
---|---|
System.String | The given value converted to a universal sortable long date time string. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | The culture can not be null. |
ToUniversalSortableLongDateTimeString(DateTime, DateTimeFormatInfo)
Converts the DateTime value to a universal sortable long date time string.
Declaration
public static string ToUniversalSortableLongDateTimeString(this DateTime dateTime, DateTimeFormatInfo formatInfo)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | The DateTime value to convert. |
System.Globalization.DateTimeFormatInfo | formatInfo | The date time format info. |
Returns
Type | Description |
---|---|
System.String | The given value converted to a universal sortable long date time string. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | The format info can not be null. |
ToYearMonthString(DateTime)
Converts the DateTime value to a year month string.
Declaration
public static string ToYearMonthString(this DateTime dateTime)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | The DateTime value to convert. |
Returns
Type | Description |
---|---|
System.String | The given value converted to a year month string. |
ToYearMonthString(DateTime, CultureInfo)
Converts the DateTime value to a year month string.
Declaration
public static string ToYearMonthString(this DateTime dateTime, CultureInfo culture)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | The DateTime value to convert. |
System.Globalization.CultureInfo | culture | The culture. |
Returns
Type | Description |
---|---|
System.String | The given value converted to a year month string. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | The culture can not be null. |
ToYearMonthString(DateTime, DateTimeFormatInfo)
Converts the DateTime value to year month string.
Declaration
public static string ToYearMonthString(this DateTime dateTime, DateTimeFormatInfo formatInfo)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | The DateTime value to convert. |
System.Globalization.DateTimeFormatInfo | formatInfo | The date time format info. |
Returns
Type | Description |
---|---|
System.String | The given value converted to year month string. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | The format info can not be null. |
Yesterday(DateTime)
Subtracts a day to the given date dateTime value.
Declaration
public static DateTime Yesterday(this DateTime dateTime)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | The date dateTime to decrease. |
Returns
Type | Description |
---|---|
System.DateTime | Yesterday date at same dateTime. |