Class DateTimeExtensions
Defines a collection of extensions for a date/time object.
Inheritance
Namespace: MADE.Data.Converters.Extensions
Assembly: MADE.Data.Converters.dll
Syntax
public static class DateTimeExtensions : object
Methods
| Improve this Doc View SourceEndOfDay(DateTime)
Gets the end of the day represented by the specified
Declaration
public static DateTime EndOfDay(this DateTime dateTime)
Parameters
Type | Name | Description |
---|---|---|
DateTime | dateTime | The |
Returns
Type | Description |
---|---|
DateTime | A new object with the same date as this instance, and the time value set to just before midnight of the next day. |
EndOfMonth(DateTime)
Gets the last day of the month represented by the specified
Declaration
public static DateTime EndOfMonth(this DateTime dateTime)
Parameters
Type | Name | Description |
---|---|---|
DateTime | dateTime | The |
Returns
Type | Description |
---|---|
DateTime | A new object with the last day of the month for this instance, and the time value set to just before midnight of the next day. |
EndOfWeek(DateTime)
Gets the last day of the week represented by the specified
Declaration
public static DateTime EndOfWeek(this DateTime dateTime)
Parameters
Type | Name | Description |
---|---|---|
DateTime | dateTime | The |
Returns
Type | Description |
---|---|
DateTime | A new object with the last day of the week for this instance, and the time value set to just before midnight of the next day. |
EndOfYear(DateTime)
Gets the last day of the year represented by the specified
Declaration
public static DateTime EndOfYear(this DateTime dateTime)
Parameters
Type | Name | Description |
---|---|---|
DateTime | dateTime | The |
Returns
Type | Description |
---|---|
DateTime | A new object with the last day of the year for this instance, and the time value set to just before midnight of the next day. |
SetTime(DateTime, Int32, Int32)
Sets the time value of a date/time value.
Declaration
public static DateTime SetTime(this DateTime dateTime, int hours, int minutes)
Parameters
Type | Name | Description |
---|---|---|
DateTime | dateTime | The date/time value to add a time to. |
System.Int32 | hours | The hours to set on the date/time value. |
System.Int32 | minutes | The minutes to set on the date/time value. |
Returns
Type | Description |
---|---|
DateTime | The updated date/time with the given time value. |
SetTime(DateTime, Int32, Int32, Int32)
Sets the time value of a date/time value.
Declaration
public static DateTime SetTime(this DateTime dateTime, int hours, int minutes, int seconds)
Parameters
Type | Name | Description |
---|---|---|
DateTime | dateTime | The date/time value to add a time to. |
System.Int32 | hours | The hours to set on the date/time value. |
System.Int32 | minutes | The minutes to set on the date/time value. |
System.Int32 | seconds | The seconds to set on the date/time value. |
Returns
Type | Description |
---|---|
DateTime | The updated date/time with the given time value. |
SetTime(DateTime, Int32, Int32, Int32, Int32)
Sets the time value of a date/time value.
Declaration
public static DateTime SetTime(this DateTime dateTime, int hours, int minutes, int seconds, int milliseconds)
Parameters
Type | Name | Description |
---|---|---|
DateTime | dateTime | The date/time value to add a time to. |
System.Int32 | hours | The hours to set on the date/time value. |
System.Int32 | minutes | The minutes to set on the date/time value. |
System.Int32 | seconds | The seconds to set on the date/time value. |
System.Int32 | milliseconds | The milliseconds to set on the date/time value. |
Returns
Type | Description |
---|---|
DateTime | The updated date/time with the given time value. |
SetTime(DateTime, TimeSpan)
Sets the time value of a date/time value.
Declaration
public static DateTime SetTime(this DateTime dateTime, TimeSpan timeSpan)
Parameters
Type | Name | Description |
---|---|---|
DateTime | dateTime | The date/time value to add a time to. |
TimeSpan | timeSpan | The time to set on the date/time value. |
Returns
Type | Description |
---|---|
DateTime | The updated date/time with the given time value. |
SetTime(Nullable<DateTime>, Int32, Int32)
Sets the time value of a nullable date/time value.
Declaration
public static DateTime? SetTime(this DateTime? dateTime, int hours, int minutes)
Parameters
Type | Name | Description |
---|---|---|
System.Nullable<DateTime> | dateTime | The nullable date/time value to add a time to. |
System.Int32 | hours | The hours to set on the date/time value. |
System.Int32 | minutes | The minutes to set on the date/time value. |
Returns
Type | Description |
---|---|
System.Nullable<DateTime> | The updated date/time with the given time value. |
SetTime(Nullable<DateTime>, Int32, Int32, Int32)
Sets the time value of a nullable date/time value.
Declaration
public static DateTime? SetTime(this DateTime? dateTime, int hours, int minutes, int seconds)
Parameters
Type | Name | Description |
---|---|---|
System.Nullable<DateTime> | dateTime | The nullable date/time value to add a time to. |
System.Int32 | hours | The hours to set on the date/time value. |
System.Int32 | minutes | The minutes to set on the date/time value. |
System.Int32 | seconds | The seconds to set on the date/time value. |
Returns
Type | Description |
---|---|
System.Nullable<DateTime> | The updated date/time with the given time value. |
SetTime(Nullable<DateTime>, Int32, Int32, Int32, Int32)
Sets the time value of a nullable date/time value.
Declaration
public static DateTime? SetTime(this DateTime? dateTime, int hours, int minutes, int seconds, int milliseconds)
Parameters
Type | Name | Description |
---|---|---|
System.Nullable<DateTime> | dateTime | The nullable date/time value to add a time to. |
System.Int32 | hours | The hours to set on the date/time value. |
System.Int32 | minutes | The minutes to set on the date/time value. |
System.Int32 | seconds | The seconds to set on the date/time value. |
System.Int32 | milliseconds | The milliseconds to set on the date/time value. |
Returns
Type | Description |
---|---|
System.Nullable<DateTime> | The updated date/time with the given time value. |
SetTime(Nullable<DateTime>, TimeSpan)
Sets the time value of a nullable date/time value.
Declaration
public static DateTime? SetTime(this DateTime? dateTime, TimeSpan timeSpan)
Parameters
Type | Name | Description |
---|---|---|
System.Nullable<DateTime> | dateTime | The nullable date/time value to add a time to. |
TimeSpan | timeSpan | The time to set on the date/time value. |
Returns
Type | Description |
---|---|
System.Nullable<DateTime> | The updated date/time with the given time value. |
StartOfDay(DateTime)
Gets the start of the day represented by the specified
Declaration
public static DateTime StartOfDay(this DateTime dateTime)
Parameters
Type | Name | Description |
---|---|---|
DateTime | dateTime | The |
Returns
Type | Description |
---|---|
DateTime | A new object with the same date as this instance, and the time value set to midnight. |
StartOfMonth(DateTime)
Gets the first day of the month represented by the specified
Declaration
public static DateTime StartOfMonth(this DateTime dateTime)
Parameters
Type | Name | Description |
---|---|---|
DateTime | dateTime | The |
Returns
Type | Description |
---|---|
DateTime | A new object with the first day of the month for this instance, and the time value set to midnight. |
StartOfWeek(DateTime)
Gets the first day of the week represented by the specified
Declaration
public static DateTime StartOfWeek(this DateTime dateTime)
Parameters
Type | Name | Description |
---|---|---|
DateTime | dateTime | The |
Returns
Type | Description |
---|---|
DateTime | A new object with the first day of the week for this instance, and the time value set to midnight. |
StartOfYear(DateTime)
Gets the first day of the year represented by the specified
Declaration
public static DateTime StartOfYear(this DateTime dateTime)
Parameters
Type | Name | Description |
---|---|---|
DateTime | dateTime | The |
Returns
Type | Description |
---|---|
DateTime | A new object with the first day of the year for this instance, and the time value set to midnight. |
ToCurrentAge(DateTime)
Gets the current age in years based on the specified starting date and today's date.
Declaration
public static int ToCurrentAge(this DateTime startingDate)
Parameters
Type | Name | Description |
---|---|---|
DateTime | startingDate | The starting date. |
Returns
Type | Description |
---|---|
System.Int32 | An integer value representing the number of years. |
ToDaySuffix(DateTime)
Gets the day suffix for the specified date, i.e. st, nd, rd, or th.
Declaration
public static string ToDaySuffix(this DateTime dateTime)
Parameters
Type | Name | Description |
---|---|---|
DateTime | dateTime | The date to get a day suffix for. |
Returns
Type | Description |
---|---|
System.String | The day suffix as a string. |
ToNearestHour(DateTime)
Rounds a
This is determined by the half hour of each hour, rounding up or down.
Declaration
public static DateTime ToNearestHour(this DateTime dateTime)
Parameters
Type | Name | Description |
---|---|---|
DateTime | dateTime | The |
Returns
Type | Description |
---|---|
DateTime | The updated |