Skip to content

DateTimeExtensions

DateTime manipulation and formatting extension methods.

API Reference

Period Boundaries

MethodReturnDescription
StartOfDay(this DateTime)DateTime00:00:00 of the day
EndOfDay(this DateTime)DateTime23:59:59.999 of the day
StartOfWeek(this DateTime, DayOfWeek)DateTimeFirst day of week
EndOfWeek(this DateTime, DayOfWeek)DateTimeLast moment of week
StartOfMonth(this DateTime)DateTimeFirst day of month
EndOfMonth(this DateTime)DateTimeLast moment of month
StartOfYear(this DateTime)DateTimeFirst day of year
EndOfYear(this DateTime)DateTimeLast moment of year

Date Checks

MethodReturnDescription
IsToday(this DateTime)boolIs current date
IsPast(this DateTime)boolBefore now
IsFuture(this DateTime)boolAfter now
IsWeekend(this DateTime)boolSaturday or Sunday
IsWeekday(this DateTime)boolMonday to Friday
IsBetween(this DateTime, DateTime, DateTime)boolWithin range

Conversions

MethodReturnDescription
ToUnixTimeSeconds(this DateTime)longUnix timestamp (seconds)
ToUnixTimeMilliseconds(this DateTime)longUnix timestamp (ms)
ToIso8601(this DateTime)stringISO 8601 format
ToRelativeTime(this DateTime)string2 hours ago
EnsureUtc(this DateTime)DateTimeEnsures UTC kind
GetAge(this DateTime)intAge in years

Released under the MIT License.