Table of Contents

Class DateTimeExtensions

Namespace
MADE.Data.Converters.Extensions
Assembly
MADE.Data.Converters.dll

Defines a collection of extensions for a date/time object.

public static class DateTimeExtensions
Inheritance
DateTimeExtensions
Inherited Members

Methods

EndOfDay(DateTime)

Gets the end of the day represented by the specified DateTime object.

public static DateTime EndOfDay(this DateTime dateTime)

Parameters

dateTime DateTime

The DateTime.

Returns

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 DateTime object.

public static DateTime EndOfMonth(this DateTime dateTime)

Parameters

dateTime DateTime

The DateTime.

Returns

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 DateTime object.

public static DateTime EndOfWeek(this DateTime dateTime)

Parameters

dateTime DateTime

The DateTime.

Returns

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 DateTime object.

public static DateTime EndOfYear(this DateTime dateTime)

Parameters

dateTime DateTime

The DateTime.

Returns

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, int, int)

Sets the time value of a date/time value.

public static DateTime SetTime(this DateTime dateTime, int hours, int minutes)

Parameters

dateTime DateTime

The date/time value to add a time to.

hours int

The hours to set on the date/time value.

minutes int

The minutes to set on the date/time value.

Returns

DateTime

The updated date/time with the given time value.

SetTime(DateTime, int, int, int)

Sets the time value of a date/time value.

public static DateTime SetTime(this DateTime dateTime, int hours, int minutes, int seconds)

Parameters

dateTime DateTime

The date/time value to add a time to.

hours int

The hours to set on the date/time value.

minutes int

The minutes to set on the date/time value.

seconds int

The seconds to set on the date/time value.

Returns

DateTime

The updated date/time with the given time value.

SetTime(DateTime, int, int, int, int)

Sets the time value of a date/time value.

public static DateTime SetTime(this DateTime dateTime, int hours, int minutes, int seconds, int milliseconds)

Parameters

dateTime DateTime

The date/time value to add a time to.

hours int

The hours to set on the date/time value.

minutes int

The minutes to set on the date/time value.

seconds int

The seconds to set on the date/time value.

milliseconds int

The milliseconds to set on the date/time value.

Returns

DateTime

The updated date/time with the given time value.

SetTime(DateTime, TimeSpan)

Sets the time value of a date/time value.

public static DateTime SetTime(this DateTime dateTime, TimeSpan timeSpan)

Parameters

dateTime DateTime

The date/time value to add a time to.

timeSpan TimeSpan

The time to set on the date/time value.

Returns

DateTime

The updated date/time with the given time value.

SetTime(DateTime?, int, int)

Sets the time value of a nullable date/time value.

public static DateTime? SetTime(this DateTime? dateTime, int hours, int minutes)

Parameters

dateTime DateTime?

The nullable date/time value to add a time to.

hours int

The hours to set on the date/time value.

minutes int

The minutes to set on the date/time value.

Returns

DateTime?

The updated date/time with the given time value.

SetTime(DateTime?, int, int, int)

Sets the time value of a nullable date/time value.

public static DateTime? SetTime(this DateTime? dateTime, int hours, int minutes, int seconds)

Parameters

dateTime DateTime?

The nullable date/time value to add a time to.

hours int

The hours to set on the date/time value.

minutes int

The minutes to set on the date/time value.

seconds int

The seconds to set on the date/time value.

Returns

DateTime?

The updated date/time with the given time value.

SetTime(DateTime?, int, int, int, int)

Sets the time value of a nullable date/time value.

public static DateTime? SetTime(this DateTime? dateTime, int hours, int minutes, int seconds, int milliseconds)

Parameters

dateTime DateTime?

The nullable date/time value to add a time to.

hours int

The hours to set on the date/time value.

minutes int

The minutes to set on the date/time value.

seconds int

The seconds to set on the date/time value.

milliseconds int

The milliseconds to set on the date/time value.

Returns

DateTime?

The updated date/time with the given time value.

SetTime(DateTime?, TimeSpan)

Sets the time value of a nullable date/time value.

public static DateTime? SetTime(this DateTime? dateTime, TimeSpan timeSpan)

Parameters

dateTime DateTime?

The nullable date/time value to add a time to.

timeSpan TimeSpan

The time to set on the date/time value.

Returns

DateTime?

The updated date/time with the given time value.

StartOfDay(DateTime)

Gets the start of the day represented by the specified DateTime object.

public static DateTime StartOfDay(this DateTime dateTime)

Parameters

dateTime DateTime

The DateTime.

Returns

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 DateTime object.

public static DateTime StartOfMonth(this DateTime dateTime)

Parameters

dateTime DateTime

The DateTime.

Returns

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 DateTime object.

public static DateTime StartOfWeek(this DateTime dateTime)

Parameters

dateTime DateTime

The DateTime.

Returns

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 DateTime object.

public static DateTime StartOfYear(this DateTime dateTime)

Parameters

dateTime DateTime

The DateTime.

Returns

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.

public static int ToCurrentAge(this DateTime startingDate)

Parameters

startingDate DateTime

The starting date.

Returns

int

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.

public static string ToDaySuffix(this DateTime dateTime)

Parameters

dateTime DateTime

The date to get a day suffix for.

Returns

string

The day suffix as a string.

ToNearestHour(DateTime)

Rounds a DateTime value to its nearest hour.

This is determined by the half hour of each hour, rounding up or down.

public static DateTime ToNearestHour(this DateTime dateTime)

Parameters

dateTime DateTime

The DateTime to round.

Returns

DateTime

The updated DateTime.