Class DateUtil
Provides a comprehensive set of static utility methods for working with DateTime values, including culture-aware formatting and parsing, date arithmetic, boundary calculations (start/end of day, week, month, year), calendar queries, human-readable relative descriptions, Unix timestamp conversions, and age calculations.
Inherited Members
Namespace: Scylla.Core.Util
Assembly: ScyllaCore.dll
Syntax
public static class DateUtil
Remarks
All formatting and parsing operations use the culture set via the Culture property, which defaults to InvariantCulture for consistent, locale-independent results. Change Culture once at application startup if you need locale-specific output (e.g., locale date separators, month names).
ISO 8601 methods (ToISO8601(DateTime, bool), ToISO8601UTC(DateTime), ParseISO8601(string)) always use InvariantCulture regardless of the Culture setting, ensuring portable interchange formats.
Predefined format constants such as FORMAT_ISO_DATE,
FORMAT_HH_MM_SS, and FORMAT_SORTABLE can be passed
directly to any method that accepts a format parameter.
Fields
FORMAT_DD_MM_YYYY
Day/Month/Year format (e.g., "15/01/2026").
Declaration
public const string FORMAT_DD_MM_YYYY = "dd/MM/yyyy"
Field Value
| Type | Description |
|---|---|
| string |
FORMAT_FULL_LONG
Full date/time long pattern.
Declaration
public const string FORMAT_FULL_LONG = "F"
Field Value
| Type | Description |
|---|---|
| string |
FORMAT_FULL_SHORT
Full date/time short pattern.
Declaration
public const string FORMAT_FULL_SHORT = "f"
Field Value
| Type | Description |
|---|---|
| string |
FORMAT_GENERAL_LONG
General date/time long pattern.
Declaration
public const string FORMAT_GENERAL_LONG = "G"
Field Value
| Type | Description |
|---|---|
| string |
FORMAT_GENERAL_SHORT
General date/time short pattern.
Declaration
public const string FORMAT_GENERAL_SHORT = "g"
Field Value
| Type | Description |
|---|---|
| string |
FORMAT_HH_MM
Time with hours and minutes (e.g., "14:30").
Declaration
public const string FORMAT_HH_MM = "HH:mm"
Field Value
| Type | Description |
|---|---|
| string |
FORMAT_HH_MM_SS
Time with hours, minutes, seconds (e.g., "14:30:00").
Declaration
public const string FORMAT_HH_MM_SS = "HH:mm:ss"
Field Value
| Type | Description |
|---|---|
| string |
FORMAT_ISO_8601_UTC
ISO 8601 UTC format (e.g., "2026-01-15T14:30:00Z").
Declaration
public const string FORMAT_ISO_8601_UTC = "yyyy-MM-ddTHH:mm:ssZ"
Field Value
| Type | Description |
|---|---|
| string |
FORMAT_ISO_DATE
ISO 8601 date format (e.g., "2026-01-15").
Declaration
public const string FORMAT_ISO_DATE = "yyyy-MM-dd"
Field Value
| Type | Description |
|---|---|
| string |
FORMAT_ISO_DATETIME
ISO 8601 date/time format (e.g., "2026-01-15T14:30:00").
Declaration
public const string FORMAT_ISO_DATETIME = "yyyy-MM-ddTHH:mm:ss"
Field Value
| Type | Description |
|---|---|
| string |
FORMAT_LONG_DATE
Long date pattern (e.g., "Wednesday, January 15, 2026").
Declaration
public const string FORMAT_LONG_DATE = "D"
Field Value
| Type | Description |
|---|---|
| string |
FORMAT_LONG_TIME
Long time pattern (e.g., "2:30:00 PM").
Declaration
public const string FORMAT_LONG_TIME = "T"
Field Value
| Type | Description |
|---|---|
| string |
FORMAT_MM_DD_YYYY
Month/Day/Year format (e.g., "01/15/2026").
Declaration
public const string FORMAT_MM_DD_YYYY = "MM/dd/yyyy"
Field Value
| Type | Description |
|---|---|
| string |
FORMAT_SHORT_DATE
Short date pattern (e.g., "1/15/2026").
Declaration
public const string FORMAT_SHORT_DATE = "d"
Field Value
| Type | Description |
|---|---|
| string |
FORMAT_SHORT_TIME
Short time pattern (e.g., "2:30 PM").
Declaration
public const string FORMAT_SHORT_TIME = "t"
Field Value
| Type | Description |
|---|---|
| string |
FORMAT_SORTABLE
Sortable date/time pattern.
Declaration
public const string FORMAT_SORTABLE = "s"
Field Value
| Type | Description |
|---|---|
| string |
FORMAT_UNIVERSAL
Universal sortable date/time pattern.
Declaration
public const string FORMAT_UNIVERSAL = "u"
Field Value
| Type | Description |
|---|---|
| string |
FORMAT_YYYY_MM_DD
Year/Month/Day format (e.g., "2026/01/15").
Declaration
public const string FORMAT_YYYY_MM_DD = "yyyy/MM/dd"
Field Value
| Type | Description |
|---|---|
| string |
FORMAT_YYYY_MM_DD_DASH
Year-Month-Day with dashes (e.g., "2026-01-15").
Declaration
public const string FORMAT_YYYY_MM_DD_DASH = "yyyy-MM-dd"
Field Value
| Type | Description |
|---|---|
| string |
UNIX_EPOCH
Unix epoch start date (January 1, 1970 00:00:00 UTC).
Declaration
public static readonly DateTime UNIX_EPOCH
Field Value
| Type | Description |
|---|---|
| DateTime |
Properties
Culture
Gets or sets the culture used for all date formatting and parsing operations performed
by this utility class. Defaults to InvariantCulture to
produce locale-independent output. Setting this to a specific culture (e.g.,
CultureInfo.GetCultureInfo("en-US")) affects month names, date separators, and
AM/PM designators in format strings that include those components.
Declaration
public static CultureInfo Culture { get; set; }
Property Value
| Type | Description |
|---|---|
| CultureInfo | The CultureInfo used for formatting and parsing. Never |
Remarks
Assigning null resets the value to InvariantCulture
rather than throwing an exception. ISO 8601 methods always use
InvariantCulture regardless of this property.
Methods
AddDays(DateTime, int)
Returns a new DateTime that adds the specified number of whole days to
dateTime. Delegates to AddDays(double).
Declaration
public static DateTime AddDays(DateTime dateTime, int days)
Parameters
| Type | Name | Description |
|---|---|---|
| DateTime | dateTime | The base date and time to add to. |
| int | days | The number of days to add. Pass a negative value to subtract days. Fractional values are not accepted because the parameter is typed as int. |
Returns
| Type | Description |
|---|---|
| DateTime | A new DateTime offset from |
AddMonths(DateTime, int)
Returns a new DateTime that adds the specified number of whole months to
dateTime, using calendar-aware arithmetic that accounts for varying
month lengths. For example, adding one month to January 31 yields February 28/29.
Delegates to AddMonths(int).
Declaration
public static DateTime AddMonths(DateTime dateTime, int months)
Parameters
| Type | Name | Description |
|---|---|---|
| DateTime | dateTime | The base date and time to add to. |
| int | months | The number of months to add. Pass a negative value to subtract months. |
Returns
| Type | Description |
|---|---|
| DateTime | A new DateTime offset by |
AddYears(DateTime, int)
Returns a new DateTime that adds the specified number of whole years to
dateTime. Handles leap-year edge cases (e.g., Feb 29 becomes Feb 28
in a non-leap target year). Delegates to AddYears(int).
Declaration
public static DateTime AddYears(DateTime dateTime, int years)
Parameters
| Type | Name | Description |
|---|---|---|
| DateTime | dateTime | The base date and time to add to. |
| int | years | The number of years to add. Pass a negative value to subtract years. |
Returns
| Type | Description |
|---|---|
| DateTime | A new DateTime offset by |
Format(DateTime, string)
Formats the specified dateTime value using the given format
string and the active Culture. Defaults to FORMAT_GENERAL_LONG
when no format is specified.
Declaration
public static string Format(DateTime dateTime, string format = "G")
Parameters
| Type | Name | Description |
|---|---|---|
| DateTime | dateTime | The DateTime value to format. |
| string | format | A standard or custom .NET date-time format pattern. Defaults to FORMAT_GENERAL_LONG.
Must not be |
Returns
| Type | Description |
|---|---|
| string | A string representation of |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown when |
FromUnixTimestamp(long)
Converts a Unix timestamp (seconds since UNIX_EPOCH) to a DateTime in UTC. The result always has Utc because UNIX_EPOCH is a UTC value.
Declaration
public static DateTime FromUnixTimestamp(long timestamp)
Parameters
| Type | Name | Description |
|---|---|---|
| long | timestamp | Seconds elapsed since 1970-01-01 00:00:00 UTC. May be negative for pre-epoch values. |
Returns
| Type | Description |
|---|---|
| DateTime | A DateTime with Utc corresponding to
|
FromUnixTimestampMilliseconds(long)
Converts a Unix timestamp in milliseconds to a DateTime in UTC. Counterpart to ToUnixTimestampMilliseconds(DateTime). The result always has Utc.
Declaration
public static DateTime FromUnixTimestampMilliseconds(long timestampMilliseconds)
Parameters
| Type | Name | Description |
|---|---|---|
| long | timestampMilliseconds | Milliseconds elapsed since 1970-01-01 00:00:00 UTC. May be negative for pre-epoch values. |
Returns
| Type | Description |
|---|---|
| DateTime | A DateTime with Utc corresponding to
|
GetAge(DateTime)
Calculates the age in complete years from birthDate to today's
date (Today). The birthday is considered to have occurred if
both the month and the day-of-month of the current date are greater than or equal to
the corresponding values of birthDate.
Declaration
public static int GetAge(DateTime birthDate)
Parameters
| Type | Name | Description |
|---|---|---|
| DateTime | birthDate | The date of birth. Only the date component is used; the time is ignored. |
Returns
| Type | Description |
|---|---|
| int | The number of complete years elapsed since |
GetAge(DateTime, DateTime)
Calculates the age in complete years from birthDate to
referenceDate. Correctly accounts for whether the birthday has
passed in the reference year by comparing month and day components.
Declaration
public static int GetAge(DateTime birthDate, DateTime referenceDate)
Parameters
| Type | Name | Description |
|---|---|---|
| DateTime | birthDate | The date of birth. Only the date component is used. |
| DateTime | referenceDate | The date at which to calculate the age. Typically today, but can be any past or future date to compute a hypothetical age. |
Returns
| Type | Description |
|---|---|
| int | The number of complete years elapsed from |
GetDayOfYear(DateTime)
Returns the one-based ordinal day number within the year (1-366) for the given
dateTime. Equivalent to dateTime.DayOfYear.
Declaration
public static int GetDayOfYear(DateTime dateTime)
Parameters
| Type | Name | Description |
|---|---|---|
| DateTime | dateTime | The DateTime to query. |
Returns
| Type | Description |
|---|---|
| int | An integer in the range 1-366 representing the day within the year. |
GetDaysBetween(DateTime, DateTime)
Returns the number of whole calendar days between two dates, ignoring the time-of-day
component. The result is computed as (end.Date - start.Date).TotalDays and can
be negative when end precedes start.
Declaration
public static int GetDaysBetween(DateTime start, DateTime end)
Parameters
| Type | Name | Description |
|---|---|---|
| DateTime | start | The earlier (or reference) date. |
| DateTime | end | The later (or target) date. |
Returns
| Type | Description |
|---|---|
| int | The signed number of whole days from |
GetDaysInMonth(DateTime)
Returns the number of days in the month of the given dateTime,
taking leap years into account for February. Delegates to
DaysInMonth(int, int).
Declaration
public static int GetDaysInMonth(DateTime dateTime)
Parameters
| Type | Name | Description |
|---|---|---|
| DateTime | dateTime | The DateTime whose month is queried. |
Returns
| Type | Description |
|---|---|
| int | 28, 29, 30, or 31 depending on the month and year. |
GetDaysInMonth(int, int)
Returns the number of days in month for the given year,
taking leap years into account. Delegates to DaysInMonth(int, int).
Declaration
public static int GetDaysInMonth(int year, int month)
Parameters
| Type | Name | Description |
|---|---|---|
| int | year | The Gregorian year. |
| int | month | The month number in the range 1-12. |
Returns
| Type | Description |
|---|---|
| int | 28, 29, 30, or 31 depending on the month and year. |
GetDaysInYear(DateTime)
Returns the total number of days in the year of dateTime.
Returns 366 for leap years and 365 for non-leap years.
Declaration
public static int GetDaysInYear(DateTime dateTime)
Parameters
| Type | Name | Description |
|---|---|---|
| DateTime | dateTime | The DateTime whose year is queried. |
Returns
| Type | Description |
|---|---|
| int | 365 or 366. |
GetDaysInYear(int)
Returns the total number of days in the specified year.
Returns 366 for leap years and 365 for non-leap years.
Declaration
public static int GetDaysInYear(int year)
Parameters
| Type | Name | Description |
|---|---|---|
| int | year | The Gregorian year to query. |
Returns
| Type | Description |
|---|---|
| int | 365 or 366. |
GetEndOfDay(DateTime)
Returns the last representable tick of the day containing dateTime,
computed as dateTime.Date.AddDays(1).AddTicks(-1)
(i.e., 23:59:59.9999999).
Declaration
public static DateTime GetEndOfDay(DateTime dateTime)
Parameters
| Type | Name | Description |
|---|---|---|
| DateTime | dateTime | Any DateTime value within the target day. |
Returns
| Type | Description |
|---|---|
| DateTime | A DateTime representing one tick before the start of the following day. |
GetEndOfMonth(DateTime)
Returns the last tick of the final day of the month containing dateTime.
Computed by advancing to the start of the next month and subtracting one tick.
Declaration
public static DateTime GetEndOfMonth(DateTime dateTime)
Parameters
| Type | Name | Description |
|---|---|---|
| DateTime | dateTime | Any DateTime value within the target month. |
Returns
| Type | Description |
|---|---|
| DateTime | A DateTime representing the last representable moment of the month. |
GetEndOfWeek(DateTime, DayOfWeek)
Returns the last tick of the final day of the calendar week that contains
dateTime, consistent with the startOfWeek convention.
Computed as GetStartOfWeek(dateTime, startOfWeek).AddDays(7).AddTicks(-1).
Declaration
public static DateTime GetEndOfWeek(DateTime dateTime, DayOfWeek startOfWeek = DayOfWeek.Sunday)
Parameters
| Type | Name | Description |
|---|---|---|
| DateTime | dateTime | Any DateTime value within the target week. |
| DayOfWeek | startOfWeek | The day of the week considered the first day. Defaults to Sunday. |
Returns
| Type | Description |
|---|---|
| DateTime | A DateTime representing the last tick of the last day of the week. |
GetEndOfYear(DateTime)
Returns the last representable tick of December 31 of the year containing
dateTime. Computed by advancing to January 1 of the next year
and subtracting one tick.
Declaration
public static DateTime GetEndOfYear(DateTime dateTime)
Parameters
| Type | Name | Description |
|---|---|---|
| DateTime | dateTime | Any DateTime value within the target year. |
Returns
| Type | Description |
|---|---|
| DateTime | A DateTime representing the last tick of December 31 of the same year. |
GetMonthsBetween(DateTime, DateTime)
Returns the number of complete calendar months between two dates, calculated as
(end.Year - start.Year) * 12 + end.Month - start.Month. The result does not
account for the day-of-month component, so a start of Jan 31 and an end of Feb 1 returns 1.
Use GetDaysBetween(DateTime, DateTime) for day-accurate intervals.
Declaration
public static int GetMonthsBetween(DateTime start, DateTime end)
Parameters
| Type | Name | Description |
|---|---|---|
| DateTime | start | The reference date. |
| DateTime | end | The target date. Can precede |
Returns
| Type | Description |
|---|---|
| int | The signed approximate number of months from |
GetQuarter(DateTime)
Returns the fiscal quarter (1-4) for the given dateTime,
based on the Gregorian calendar. Q1 = Jan-Mar, Q2 = Apr-Jun, Q3 = Jul-Sep,
Q4 = Oct-Dec. Computed as (month - 1) / 3 + 1.
Declaration
public static int GetQuarter(DateTime dateTime)
Parameters
| Type | Name | Description |
|---|---|---|
| DateTime | dateTime | The DateTime to query. |
Returns
| Type | Description |
|---|---|
| int | An integer in the range 1-4 representing the calendar quarter. |
GetRelativeDescription(DateTime)
Returns a plain-English sentence describing how dateTime relates to
the current local time (Now). The description is always in
English regardless of the active Culture setting.
Declaration
public static string GetRelativeDescription(DateTime dateTime)
Parameters
| Type | Name | Description |
|---|---|---|
| DateTime | dateTime | The DateTime value to describe relative to now. |
Returns
| Type | Description |
|---|---|
| string | A human-readable phrase such as |
GetRelativeDescription(DateTime, DateTime)
Returns a plain-English sentence describing how dateTime relates to
referenceTime. Output is in English regardless of Culture.
The description uses the following threshold ladder:
- Less than 60 seconds:
"just now" - Less than 60 minutes:
"N minute(s) ago"/"in N minute(s)" - Less than 24 hours:
"N hour(s) ago"/"in N hour(s)" - Less than 7 days:
"N day(s) ago"/"in N day(s)" - Less than 30 days:
"N week(s) ago"/"in N week(s)" - Less than 365 days:
"N month(s) ago"/"in N month(s)" - 365+ days:
"N year(s) ago"/"in N year(s)"
Declaration
public static string GetRelativeDescription(DateTime dateTime, DateTime referenceTime)
Parameters
| Type | Name | Description |
|---|---|---|
| DateTime | dateTime | The DateTime to describe. |
| DateTime | referenceTime | The reference point to measure from (e.g., Now for real-time descriptions). |
Returns
| Type | Description |
|---|---|
| string | A human-readable phrase describing the temporal distance and direction. |
GetStartOfDay(DateTime)
Returns the midnight boundary of the day containing dateTime,
equivalent to dateTime.Date. The DateTimeKind of the original
value is preserved.
Declaration
public static DateTime GetStartOfDay(DateTime dateTime)
Parameters
| Type | Name | Description |
|---|---|---|
| DateTime | dateTime | Any DateTime value within the target day. |
Returns
| Type | Description |
|---|---|
| DateTime | A DateTime with the same year, month, and day as |
GetStartOfMonth(DateTime)
Returns midnight on the first day of the month containing dateTime.
The DateTimeKind of the original value is preserved.
Declaration
public static DateTime GetStartOfMonth(DateTime dateTime)
Parameters
| Type | Name | Description |
|---|---|---|
| DateTime | dateTime | Any DateTime value within the target month. |
Returns
| Type | Description |
|---|---|
| DateTime | A DateTime at |
GetStartOfWeek(DateTime, DayOfWeek)
Returns the midnight of the first day of the calendar week that contains
dateTime, using startOfWeek to define which
day opens the week. Defaults to Sunday, consistent with US conventions;
pass Monday for ISO 8601 week boundaries.
Declaration
public static DateTime GetStartOfWeek(DateTime dateTime, DayOfWeek startOfWeek = DayOfWeek.Sunday)
Parameters
| Type | Name | Description |
|---|---|---|
| DateTime | dateTime | Any DateTime value within the target week. |
| DayOfWeek | startOfWeek | The day of the week considered the first day. Defaults to Sunday. |
Returns
| Type | Description |
|---|---|
| DateTime | A DateTime at midnight ( |
GetStartOfYear(DateTime)
Returns midnight on January 1 of the year containing dateTime.
The DateTimeKind of the original value is preserved.
Declaration
public static DateTime GetStartOfYear(DateTime dateTime)
Parameters
| Type | Name | Description |
|---|---|---|
| DateTime | dateTime | Any DateTime value within the target year. |
Returns
| Type | Description |
|---|---|
| DateTime | A DateTime at |
GetWeekOfYear(DateTime, CalendarWeekRule, DayOfWeek)
Returns the week number of the year for dateTime according to the
specified rule and firstDayOfWeek.
Uses the calendar of the active Culture.
The range is 1-53 depending on the rule and year.
Declaration
public static int GetWeekOfYear(DateTime dateTime, CalendarWeekRule rule = CalendarWeekRule.FirstDay, DayOfWeek firstDayOfWeek = DayOfWeek.Sunday)
Parameters
| Type | Name | Description |
|---|---|---|
| DateTime | dateTime | The DateTime to query. |
| CalendarWeekRule | rule | Determines how the first week of the year is identified. Defaults to FirstDay (week 1 = any week containing Jan 1). |
| DayOfWeek | firstDayOfWeek | The day considered the start of the week. Defaults to Sunday. |
Returns
| Type | Description |
|---|---|
| int | The week-of-year number (1-53). |
GetYearsBetween(DateTime, DateTime)
Returns the number of complete calendar years elapsed from start to
end, accounting for whether the anniversary month and day have been
reached in the ending year. The result is always a whole number and can be negative.
Declaration
public static int GetYearsBetween(DateTime start, DateTime end)
Parameters
| Type | Name | Description |
|---|---|---|
| DateTime | start | The reference date (e.g., a birth date). |
| DateTime | end | The target date. Can precede |
Returns
| Type | Description |
|---|---|
| int | The signed number of complete years from |
IsFuture(DateTime)
Determines whether the specified DateTime is in the future.
Declaration
public static bool IsFuture(DateTime dateTime)
Parameters
| Type | Name | Description |
|---|---|---|
| DateTime | dateTime | The DateTime to check. |
Returns
| Type | Description |
|---|---|
| bool | True if the date is in the future; otherwise, false. |
IsLeapYear(DateTime)
Determines whether the year of the specified DateTime is a leap year.
Declaration
public static bool IsLeapYear(DateTime dateTime)
Parameters
| Type | Name | Description |
|---|---|---|
| DateTime | dateTime | The DateTime to check. |
Returns
| Type | Description |
|---|---|
| bool | True if the year is a leap year; otherwise, false. |
IsLeapYear(int)
Determines whether the specified year is a leap year.
Declaration
public static bool IsLeapYear(int year)
Parameters
| Type | Name | Description |
|---|---|---|
| int | year | The year to check. |
Returns
| Type | Description |
|---|---|
| bool | True if the year is a leap year; otherwise, false. |
IsPast(DateTime)
Determines whether the specified DateTime is in the past.
Declaration
public static bool IsPast(DateTime dateTime)
Parameters
| Type | Name | Description |
|---|---|---|
| DateTime | dateTime | The DateTime to check. |
Returns
| Type | Description |
|---|---|
| bool | True if the date is in the past; otherwise, false. |
IsSameDay(DateTime, DateTime)
Determines whether two DateTimes are on the same day.
Declaration
public static bool IsSameDay(DateTime date1, DateTime date2)
Parameters
| Type | Name | Description |
|---|---|---|
| DateTime | date1 | The first DateTime. |
| DateTime | date2 | The second DateTime. |
Returns
| Type | Description |
|---|---|
| bool | True if both dates are on the same day; otherwise, false. |
IsSameMonth(DateTime, DateTime)
Determines whether two DateTimes are in the same month and year.
Declaration
public static bool IsSameMonth(DateTime date1, DateTime date2)
Parameters
| Type | Name | Description |
|---|---|---|
| DateTime | date1 | The first DateTime. |
| DateTime | date2 | The second DateTime. |
Returns
| Type | Description |
|---|---|
| bool | True if both dates are in the same month; otherwise, false. |
IsSameYear(DateTime, DateTime)
Determines whether two DateTimes are in the same year.
Declaration
public static bool IsSameYear(DateTime date1, DateTime date2)
Parameters
| Type | Name | Description |
|---|---|---|
| DateTime | date1 | The first DateTime. |
| DateTime | date2 | The second DateTime. |
Returns
| Type | Description |
|---|---|
| bool | True if both dates are in the same year; otherwise, false. |
IsToday(DateTime)
Determines whether the specified DateTime is today.
Declaration
public static bool IsToday(DateTime dateTime)
Parameters
| Type | Name | Description |
|---|---|---|
| DateTime | dateTime | The DateTime to check. |
Returns
| Type | Description |
|---|---|
| bool | True if the date is today; otherwise, false. |
IsWeekday(DateTime)
Determines whether the specified date falls on a weekday (Monday through Friday).
Declaration
public static bool IsWeekday(DateTime dateTime)
Parameters
| Type | Name | Description |
|---|---|---|
| DateTime | dateTime | The DateTime to check. |
Returns
| Type | Description |
|---|---|
| bool | True if the date is a weekday; otherwise, false. |
IsWeekend(DateTime)
Determines whether the specified date falls on a weekend (Saturday or Sunday).
Declaration
public static bool IsWeekend(DateTime dateTime)
Parameters
| Type | Name | Description |
|---|---|---|
| DateTime | dateTime | The DateTime to check. |
Returns
| Type | Description |
|---|---|
| bool | True if the date is a weekend; otherwise, false. |
NowString(string)
Returns the current local date and time formatted with the specified format
string, defaulting to FORMAT_GENERAL_LONG (e.g., "1/15/2026 2:30:00 PM").
Unlike TodayString(), this includes the time-of-day component.
Declaration
public static string NowString(string format = "G")
Parameters
| Type | Name | Description |
|---|---|---|
| string | format | A standard or custom .NET date-time format pattern. Defaults to FORMAT_GENERAL_LONG.
Must not be |
Returns
| Type | Description |
|---|---|
| string | The current date and time formatted according to |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown when |
Parse(string, string)
Parses dateString using the specified format
and the active Culture.
Uses ParseExact(string, string, IFormatProvider, DateTimeStyles)
with None, so the string must match the format exactly.
Defaults to FORMAT_ISO_DATE when no format is given.
Declaration
public static DateTime Parse(string dateString, string format = "yyyy-MM-dd")
Parameters
| Type | Name | Description |
|---|---|---|
| string | dateString | The date string to parse. Must not be |
| string | format | The exact format pattern the string is expected to match.
Defaults to FORMAT_ISO_DATE ( |
Returns
| Type | Description |
|---|---|
| DateTime | The DateTime value parsed from |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown when |
| FormatException | Thrown when |
ParseISO8601(string)
Parses an ISO 8601 formatted string using Parse(string, IFormatProvider, DateTimeStyles)
with RoundtripKind and InvariantCulture.
Accepts the full range of ISO 8601 variants including date-only ("2026-01-15"),
date-time ("2026-01-15T14:30:00"), and UTC-offset forms ("2026-01-15T14:30:00Z").
The RoundtripKind style preserves DateTimeKind information embedded in the string.
Declaration
public static DateTime ParseISO8601(string isoString)
Parameters
| Type | Name | Description |
|---|---|---|
| string | isoString | An ISO 8601 formatted date or date-time string. Must not be |
Returns
| Type | Description |
|---|---|
| DateTime | The DateTime value represented by |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown when |
| FormatException | Thrown when |
ToISO8601(DateTime, bool)
Formats the specified dateTime as an ISO 8601 string using
InvariantCulture (unaffected by Culture).
When includeTime is true, uses
FORMAT_ISO_DATETIME (e.g., "2026-01-15T14:30:00").
When false, uses FORMAT_ISO_DATE (e.g., "2026-01-15").
Declaration
public static string ToISO8601(DateTime dateTime, bool includeTime = true)
Parameters
| Type | Name | Description |
|---|---|---|
| DateTime | dateTime | The DateTime value to convert. No UTC conversion is applied; the value is formatted as-is. |
| bool | includeTime |
|
Returns
| Type | Description |
|---|---|
| string | An ISO 8601 formatted string representation of |
ToISO8601UTC(DateTime)
Converts the specified dateTime to UTC and formats it as an ISO 8601
UTC string using the FORMAT_ISO_8601_UTC pattern
(e.g., "2026-01-15T14:30:00Z"). Always uses InvariantCulture.
Declaration
public static string ToISO8601UTC(DateTime dateTime)
Parameters
| Type | Name | Description |
|---|---|---|
| DateTime | dateTime | The DateTime value to convert. If the value's |
Returns
| Type | Description |
|---|---|
| string | An ISO 8601 UTC-formatted string ending with the |
ToUnixTimestamp(DateTime)
Converts dateTime to a Unix timestamp - the number of whole seconds
elapsed since the Unix epoch (UNIX_EPOCH, 1970-01-01 00:00:00 UTC).
The input is first converted to UTC via ToUniversalTime().
Declaration
public static long ToUnixTimestamp(DateTime dateTime)
Parameters
| Type | Name | Description |
|---|---|---|
| DateTime | dateTime | The date and time to convert. If |
Returns
| Type | Description |
|---|---|
| long | A signed 64-bit integer representing seconds since the Unix epoch. Negative for dates before 1970-01-01 UTC. |
ToUnixTimestampMilliseconds(DateTime)
Converts dateTime to a Unix timestamp in milliseconds - the number
of whole milliseconds elapsed since UNIX_EPOCH (1970-01-01 00:00:00 UTC).
The input is first converted to UTC. Use this for JavaScript Date.getTime()
interoperability or when second-precision is insufficient.
Declaration
public static long ToUnixTimestampMilliseconds(DateTime dateTime)
Parameters
| Type | Name | Description |
|---|---|---|
| DateTime | dateTime | The date and time to convert. Converted to UTC before calculation. |
Returns
| Type | Description |
|---|---|
| long | A signed 64-bit integer representing milliseconds since the Unix epoch. |
TodayString()
Returns the current local date formatted with the FORMAT_SHORT_DATE pattern
(e.g., "1/15/2026" with InvariantCulture).
The output is culture-sensitive if Culture has been changed from its default.
Declaration
public static string TodayString()
Returns
| Type | Description |
|---|---|
| string | The current date as a short-date string using the active Culture. |
TodayString(string)
Returns the current local date formatted with the specified format string.
Use one of the predefined FORMAT_* constants or a custom .NET date-format pattern.
Declaration
public static string TodayString(string format)
Parameters
| Type | Name | Description |
|---|---|---|
| string | format | A standard or custom .NET date-format pattern (e.g., FORMAT_ISO_DATE,
FORMAT_LONG_DATE). Must not be |
Returns
| Type | Description |
|---|---|
| string | The current date formatted according to |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown when |
TryParse(string, out DateTime, string)
Attempts to parse dateString using the specified format
and the active Culture, without throwing on failure.
Returns false and sets result to
MinValue when the input is null, empty, or does not
match the format.
Declaration
public static bool TryParse(string dateString, out DateTime result, string format = "yyyy-MM-dd")
Parameters
| Type | Name | Description |
|---|---|---|
| string | dateString | The date string to parse. Returns |
| DateTime | result | When this method returns |
| string | format | The exact format pattern the string must match.
Defaults to FORMAT_ISO_DATE. Returns |
Returns
| Type | Description |
|---|---|
| bool |
|
TryParseAny(string, out DateTime)
Attempts to parse dateString against multiple commonly used date formats
in a single call. Tries formats in the following order:
FORMAT_ISO_DATE, FORMAT_ISO_DATETIME,
FORMAT_DD_MM_YYYY, FORMAT_MM_DD_YYYY,
FORMAT_YYYY_MM_DD, FORMAT_YYYY_MM_DD_DASH,
and FORMAT_SORTABLE.
Returns false and sets result to MinValue
when none of the formats match or the input is null or empty.
Declaration
public static bool TryParseAny(string dateString, out DateTime result)
Parameters
| Type | Name | Description |
|---|---|---|
| string | dateString | The date string to attempt parsing. Returns |
| DateTime | result | When this method returns |
Returns
| Type | Description |
|---|---|
| bool |
|