---
title: DateRange
summary: API reference for DateRange.
status: draft
owner: SAIF
last_reviewed: 2026-07-24
library: SAIF.Business
reference_type: package
---

# DateRange

`DateRange` is a public class in `SAIF.Business` that inherits `clsBusinessBase`, implements `IDateRange`, and stores a begin date and end date as smart dates.

## Purpose
- Represents a begin/end date pair through the `IDateRange` contract.
- Supports ordering, equality, parsing, and string formatting for date-range values.
- Tracks original smart-date values and dirty state so callers can detect modifications.

## Context
- Namespace: `SAIF.Business`
- Assembly/package: `SAIF.Business`

## Public members
| Member | Signature | Purpose |
| --- | --- | --- |
| `<=` | `Public Shared Operator <=(ByVal d1 As DateRange, ByVal d2 As DateRange) As Boolean` | Compares two ranges by begin date and then by end date to determine whether the first range sorts before or matches the second. |
| `>=` | `Public Shared Operator >=(ByVal d1 As DateRange, ByVal d2 As DateRange) As Boolean` | Compares two ranges by begin date and then by end date to determine whether the first range sorts after or matches the second. |
| `<` | `Public Shared Operator <(ByVal d1 As DateRange, ByVal d2 As DateRange) As Boolean` | Compares two ranges by begin date and then by end date to determine whether the first range sorts before the second. |
| `>` | `Public Shared Operator >(ByVal d1 As DateRange, ByVal d2 As DateRange) As Boolean` | Compares two ranges by begin date and then by end date to determine whether the first range sorts after the second. |
| `=` | `Public Shared Operator =(ByVal d1 As DateRange, ByVal d2 As DateRange) As Boolean` | Returns `True` when both the begin date and end date match exactly. |
| `<>` | `Public Shared Operator <>(ByVal d1 As DateRange, ByVal d2 As DateRange) As Boolean` | Returns `True` when either the begin date or end date differs. |
| `BeginDate` | `Public Property BeginDate() As Date Implements IDateRange.BeginDate` | Gets or sets the range begin date and marks the object dirty when the value changes. |
| `EndDate` | `Public Property EndDate() As Date Implements IDateRange.EndDate` | Gets or sets the range end date and marks the object dirty when the value changes. |
| `DefaultToStringDelimiter` | `Public Const DefaultToStringDelimiter As String = "-"` | Defines the default delimiter used by the `ToString` overloads and `Parse`. |
| `ToString` | `Public Overridable Overloads Function ToString(Optional ByVal delimiter As String = DefaultToStringDelimiter) As String` | Returns the begin date and end date as short-date strings separated by the chosen delimiter. |
| `ToString` | `Public Overridable Overloads Function ToString(ByVal beginDateFormat As String, ByVal endDateFormat As String, Optional ByVal delimiter As String = DefaultToStringDelimiter) As String` | Returns the begin date and end date formatted with explicit format strings and joined by the chosen delimiter. |
| `New` | `Public Sub New()` | Initializes an empty date range. |
| `New` | `Public Sub New(ByVal inDateRange As IDateRange)` | Initializes a date range by copying the begin and end dates from another `IDateRange`. |
| `New` | `Public Sub New(ByVal inBeginDate As Date)` | Initializes a date range with only a begin date. |
| `New` | `Public Sub New(ByVal inBeginDate As Date, ByVal inEndDate As Date)` | Initializes a date range with both a begin date and an end date. |
| `Parse` | `Public Shared Function Parse(ByVal inDate As String, Optional ByVal delimiter As String = DefaultToStringDelimiter) As DateRange` | Parses one or two date values from a delimited string and returns a corresponding `DateRange`. |
| `SetOriginal` | `Public Sub SetOriginal(Optional ByVal inBeginDate As Boolean = True, Optional ByVal inEndDate As Boolean = True)` | Marks the current begin and/or end date values as the original smart-date values. |
| `GetOriginalRange` | `Public Function GetOriginalRange() As DateRange` | Returns a new `DateRange` built from the original smart-date values. |
| `IsEndDateNull` | `Public Function IsEndDateNull() As Boolean Implements IDateRange.IsEndDateNull` | Returns whether the end date smart value is empty. |
| `IsStartDateNull` | `Public Function IsStartDateNull() As Boolean Implements IDateRange.IsBeginDateNull` | Returns whether the begin date smart value is empty. |
| `IsDirty` | `Public Overrides ReadOnly Property IsDirty As Boolean` | Returns whether either smart-date value has been modified since it was marked original. |
| `Empty` | `Public Shared ReadOnly Property Empty() As DateRange` | Returns the shared empty `DateRange` instance. |

## Behavioral notes
- The comparison operators use `BeginDate` as the primary sort key and `EndDate` as the secondary sort key.
- `BeginDate` and `EndDate` call `MarkDirty()` only when `clsSmartDate.SetValue(...)` reports that the value changed.
- `Parse` splits on the supplied delimiter, uses `CDate` for conversion, and silently returns `New DateRange()` if any exception occurs.
- `SetOriginal` can reset the original-state markers for either date independently, and `GetOriginalRange` reconstructs a new object from those original values.

## Constraints and usage notes
- `Parse` does not surface conversion errors, so callers must validate the returned object if parse failure needs to be distinguished from an intentionally empty range.
- `Empty` returns a shared singleton instance rather than creating a new object on each call.
- The no-argument constructor leaves both smart-date fields at their default state until callers assign values.

## Sources
- `Business\SAIF.Business\DateRange.vb`
