DateTimeExtensions Class

Provides extension methods for instances of DateTime.

public static class DateTimeExtensions

Methods

NameDescription
DateTime.GetEndOfDay()Given a date and time, returns the last tick of the day.
DateTime.GetEndOfMonth()Given a date and time, returns the last tick of the last day of the same month.
DateTime.GetEndOfWeek()Given a date and time, returns the last tick of the last day of the same week, according to the current culture.
DateTime.GetEndOfWeek(DayOfWeek)Returns the last tick of the earliest date, greater or equal to a given date, whose day of the week is the one preceding a specified day of the week.
DateTime.GetEndOfWeek(CultureInfo)Given a date and time, returns the last tick of the last day of the same week, according to the specified culture.
DateTime.GetEndOfWeek(DateTimeFormatInfo)Given a date and time, returns the last tick of the last day of the same week, according to the specified formatting information.
DateTime.GetLastDayOfMonth()Given a date and time, returns midnight on the last day of the same month.
DateTime.GetLastDayOfWeek()Given a date and time, returns midnight on the last day of the same week, according to the current culture.
DateTime.GetLastDayOfWeek(DayOfWeek)Returns midnight on the earliest date, greater or equal to a given date and time, whose day of the week is the one preceding a specified day of the week.
DateTime.GetLastDayOfWeek(CultureInfo)Given a date and time, returns midnight on the last day of the same week, according to the specified culture.
DateTime.GetLastDayOfWeek(DateTimeFormatInfo)Given a date and time, returns midnight on the last day of the same week, according to the specified formatting information.
DateTime.GetStartOfMonth()Given a date and time, returns midnight on the first day of the same month.
DateTime.GetStartOfWeek()Given a date and time, returns midnight on the first day of the same week, according to the current culture.
DateTime.GetStartOfWeek(DayOfWeek)Returns midnight on the most recent date, earlier or equal to a given date, whose day of the week is equal to a specified day of the week.
DateTime.GetStartOfWeek(CultureInfo)Given a date and time, returns midnight on the first day of the same week, according to the specified culture.
DateTime.GetStartOfWeek(DateTimeFormatInfo)Given a date and time, returns midnight on the first day of the same week, according to the specified formatting information.

DateTime.GetEndOfDay()

Given a date and time, returns the last tick of the day.

extension(DateTime @this)
{
    public DateTime GetEndOfDay()
}

Parameters

this DateTime
The instance of DateTime on which this method is called.

Returns

DateTime An instance of DateTime whose value represents the last tick on the same day as this.

DateTime.GetEndOfMonth()

Given a date and time, returns the last tick of the last day of the same month.

extension(DateTime @this)
{
    public DateTime GetEndOfMonth()
}

Parameters

this DateTime
The instance of DateTime on which this method is called.

Returns

DateTime An instance of DateTime whose value represents the last tick of the last day of the month of this.

DateTime.GetEndOfWeek overloads

DateTime.GetEndOfWeek()

Given a date and time, returns the last tick of the last day of the same week, according to the current culture.

extension(DateTime @this)
{
    public DateTime GetEndOfWeek()
}
Parameters
this DateTime
The instance of DateTime on which this method is called.
Returns

DateTime An instance of DateTime whose value represents the last day of the week of this, according to the current culture.

See also

DateTime.GetEndOfWeek(DayOfWeek)

Returns the last tick of the earliest date, greater or equal to a given date, whose day of the week is the one preceding a specified day of the week.

extension(DateTime @this)
{
    public DateTime GetEndOfWeek(DayOfWeek firstDayOfWeek)
}
Parameters
this DateTime
The instance of DateTime on which this method is called.
firstDayOfWeek DayOfWeek
A DayOfWeek value representing the day that starts the week.
Returns

DateTime An instance of DateTime whose value represents the last day of the week of this, if weeks are considered starting with firstDayOfWeek.

See also

DateTime.GetEndOfWeek(CultureInfo)

Given a date and time, returns the last tick of the last day of the same week, according to the specified culture.

extension(DateTime @this)
{
    public DateTime GetEndOfWeek(CultureInfo culture)
}
Parameters
this DateTime
The instance of DateTime on which this method is called.
culture CultureInfo
An object that supplies culture-specific information.
Returns

DateTime An instance of DateTime whose value represents the last day of the week of this, according to culture.

Exceptions
ArgumentNullException
culture is null.
See also

DateTime.GetEndOfWeek(DateTimeFormatInfo)

Given a date and time, returns the last tick of the last day of the same week, according to the specified formatting information.

extension(DateTime @this)
{
    public DateTime GetEndOfWeek(DateTimeFormatInfo dateTimeFormat)
}
Parameters
this DateTime
The instance of DateTime on which this method is called.
dateTimeFormat DateTimeFormatInfo
An object that supplies culture-specific date formatting information.
Returns

DateTime An instance of DateTime whose value represents the last day of the week of this, according to dateTimeFormat.

Exceptions
ArgumentNullException
dateTimeFormat is null.
See also

DateTime.GetLastDayOfMonth()

Given a date and time, returns midnight on the last day of the same month.

extension(DateTime @this)
{
    public DateTime GetLastDayOfMonth()
}

Parameters

this DateTime
The instance of DateTime on which this method is called.

Returns

DateTime An instance of DateTime whose value represents midnight on the last day of the month of this.

DateTime.GetLastDayOfWeek overloads

DateTime.GetLastDayOfWeek()

Given a date and time, returns midnight on the last day of the same week, according to the current culture.

extension(DateTime @this)
{
    public DateTime GetLastDayOfWeek()
}
Parameters
this DateTime
The instance of DateTime on which this method is called.
Returns

DateTime An instance of DateTime whose value represents the last day of the week of this, according to the current culture.

See also

DateTime.GetLastDayOfWeek(DayOfWeek)

Returns midnight on the earliest date, greater or equal to a given date and time, whose day of the week is the one preceding a specified day of the week.

extension(DateTime @this)
{
    public DateTime GetLastDayOfWeek(DayOfWeek firstDayOfWeek)
}
Parameters
this DateTime
The instance of DateTime on which this method is called.
firstDayOfWeek DayOfWeek
A DayOfWeek value representing the day that starts the week.
Returns

DateTime An instance of DateTime whose value represents the last day of the week of this, if weeks are considered starting with firstDayOfWeek.

See also

DateTime.GetLastDayOfWeek(CultureInfo)

Given a date and time, returns midnight on the last day of the same week, according to the specified culture.

extension(DateTime @this)
{
    public DateTime GetLastDayOfWeek(CultureInfo culture)
}
Parameters
this DateTime
The instance of DateTime on which this method is called.
culture CultureInfo
An object that supplies culture-specific information.
Returns

DateTime An instance of DateTime whose value represents the last day of the week of this, according to culture.

Exceptions
ArgumentNullException
culture is null.
See also

DateTime.GetLastDayOfWeek(DateTimeFormatInfo)

Given a date and time, returns midnight on the last day of the same week, according to the specified formatting information.

extension(DateTime @this)
{
    public DateTime GetLastDayOfWeek(DateTimeFormatInfo dateTimeFormat)
}
Parameters
this DateTime
The instance of DateTime on which this method is called.
dateTimeFormat DateTimeFormatInfo
An object that supplies culture-specific date formatting information.
Returns

DateTime An instance of DateTime whose value represents the last day of the week of this, according to dateTimeFormat.

Exceptions
ArgumentNullException
dateTimeFormat is null.
See also

DateTime.GetStartOfMonth()

Given a date and time, returns midnight on the first day of the same month.

extension(DateTime @this)
{
    public DateTime GetStartOfMonth()
}

Parameters

this DateTime
The instance of DateTime on which this method is called.

Returns

DateTime An instance of DateTime whose value represents midnight on the first day of the month of this.

DateTime.GetStartOfWeek overloads

DateTime.GetStartOfWeek()

Given a date and time, returns midnight on the first day of the same week, according to the current culture.

extension(DateTime @this)
{
    public DateTime GetStartOfWeek()
}
Parameters
this DateTime
The instance of DateTime on which this method is called.
Returns

DateTime An instance of DateTime whose value represents the first day of the week of this, according to the current culture.

See also

DateTime.GetStartOfWeek(DayOfWeek)

Returns midnight on the most recent date, earlier or equal to a given date, whose day of the week is equal to a specified day of the week.

extension(DateTime @this)
{
    public DateTime GetStartOfWeek(DayOfWeek firstDayOfWeek)
}
Parameters
this DateTime
The instance of DateTime on which this method is called.
firstDayOfWeek DayOfWeek
A DayOfWeek value representing the day that starts the week.
Returns

DateTime An instance of DateTime whose value represents the first day of the week of this, if weeks are considered starting with firstDayOfWeek.

See also

DateTime.GetStartOfWeek(CultureInfo)

Given a date and time, returns midnight on the first day of the same week, according to the specified culture.

extension(DateTime @this)
{
    public DateTime GetStartOfWeek(CultureInfo culture)
}
Parameters
this DateTime
The instance of DateTime on which this method is called.
culture CultureInfo
An object that supplies culture-specific information.
Returns

DateTime An instance of DateTime whose value represents the first day of the week of this, according to culture.

Exceptions
ArgumentNullException
culture is null.
See also

DateTime.GetStartOfWeek(DateTimeFormatInfo)

Given a date and time, returns midnight on the first day of the same week, according to the specified formatting information.

extension(DateTime @this)
{
    public DateTime GetStartOfWeek(DateTimeFormatInfo dateTimeFormat)
}
Parameters
this DateTime
The instance of DateTime on which this method is called.
dateTimeFormat DateTimeFormatInfo
An object that supplies culture-specific date formatting information.
Returns

DateTime An instance of DateTime whose value represents the first day of the week of this, according to dateTimeFormat.

Exceptions
ArgumentNullException
dateTimeFormat is null.
See also