DateTimeExtensions Class

Provides extension methods for DateTime to perform common date manipulations.

public static class DateTimeExtensions

Methods

NameDescription
EndOfMonth(DateTime)Returns the last day of the month for the specified date at midnight.
StartOfMonth(DateTime)Returns the first day of the month for the specified date at midnight.
StartOfMonth(DateTime, bool)Returns the first day of the month for the specified date, optionally keeping the time component.
StartOfWeek(DateTime)Returns the start of the week for the specified date using the current culture's first day of week.
StartOfWeek(DateTime, DayOfWeek)Returns the start of the week for the specified date using the specified first day of week.
StartOfYear(DateTime)Returns the first day of the year for the specified date at midnight.
StartOfYear(DateTime, bool)Returns the first day of the year for the specified date, optionally keeping the time component.
ToStringInvariant(DateOnly)
ToStringInvariant(DateOnly, string)
ToStringInvariant(DateTime)
ToStringInvariant(DateTime, string)
ToStringInvariant(TimeOnly)
ToStringInvariant(TimeOnly, string)
TruncateMilliseconds(DateTime)Returns a new DateTime with the milliseconds component set to zero.

EndOfMonth(DateTime)

DateTimeExtensions.cs

Returns the last day of the month for the specified date at midnight.

public static DateTime EndOfMonth(this DateTime dt)

Parameters

dt DateTime

Returns

DateTime

StartOfMonth overloads

StartOfMonth(DateTime)

DateTimeExtensions.cs

Returns the first day of the month for the specified date at midnight.

public static DateTime StartOfMonth(this DateTime dt)
Parameters
dt DateTime
Returns

DateTime

StartOfMonth(DateTime, bool)

DateTimeExtensions.cs

Returns the first day of the month for the specified date, optionally keeping the time component.

public static DateTime StartOfMonth(this DateTime dt, bool keepTime)
Parameters
dt DateTime
keepTime bool
Returns

DateTime

StartOfWeek overloads

StartOfWeek(DateTime)

DateTimeExtensions.cs

Returns the start of the week for the specified date using the current culture's first day of week.

public static DateTime StartOfWeek(this DateTime dt)
Parameters
dt DateTime
Returns

DateTime

StartOfWeek(DateTime, DayOfWeek)

DateTimeExtensions.cs

Returns the start of the week for the specified date using the specified first day of week.

public static DateTime StartOfWeek(this DateTime dt, DayOfWeek startOfWeek)
Parameters
dt DateTime
startOfWeek DayOfWeek
Returns

DateTime

StartOfYear overloads

StartOfYear(DateTime)

DateTimeExtensions.cs

Returns the first day of the year for the specified date at midnight.

public static DateTime StartOfYear(this DateTime dt)
Parameters
dt DateTime
Returns

DateTime

StartOfYear(DateTime, bool)

DateTimeExtensions.cs

Returns the first day of the year for the specified date, optionally keeping the time component.

public static DateTime StartOfYear(this DateTime dt, bool keepTime)
Parameters
dt DateTime
keepTime bool
Returns

DateTime

ToStringInvariant overloads

ToStringInvariant(DateOnly)

DateTimeExtensions.cs
public static string ToStringInvariant(this DateOnly date)
Parameters
date DateOnly
Returns

string

No documentation is available.

ToStringInvariant(DateOnly, string)

DateTimeExtensions.cs
public static string ToStringInvariant(this DateOnly date, string format)
Parameters
date DateOnly
format string
Returns

string

No documentation is available.

ToStringInvariant(DateTime)

DateTimeExtensions.cs
public static string ToStringInvariant(this DateTime dt)
Parameters
dt DateTime
Returns

string

No documentation is available.

ToStringInvariant(DateTime, string)

DateTimeExtensions.cs
public static string ToStringInvariant(this DateTime dt, string format)
Parameters
dt DateTime
format string
Returns

string

No documentation is available.

ToStringInvariant(TimeOnly)

DateTimeExtensions.cs
public static string ToStringInvariant(this TimeOnly time)
Parameters
time TimeOnly
Returns

string

No documentation is available.

ToStringInvariant(TimeOnly, string)

DateTimeExtensions.cs
public static string ToStringInvariant(this TimeOnly time, string format)
Parameters
time TimeOnly
format string
Returns

string

No documentation is available.

TruncateMilliseconds(DateTime)

DateTimeExtensions.cs

Returns a new DateTime with the milliseconds component set to zero.

public static DateTime TruncateMilliseconds(this DateTime dt)

Parameters

dt DateTime

Returns

DateTime