---
title: DateTimeProvider
slug: configured-commerce/docs/datetimeprovider
docTags: 
createdAt: 2026-08-13T10:46:17.000Z
---

## Description

A provider that returns the current `DateTimeOffset` for the application. This provider should be used whenever you need to get the current date or time, rather than using the standard `DateTime `or `DateTimeOffset` classes. Using this provider also gives the additional benefit of making unit testing much easier. Before your test harness runs, you can change the current `DateTimeProvider` to a provider that returns the same `DateTimeOffset` no matter what. This makes testing for specific dates and times much easier to predict rather than using the system clock, which is always changing.

## Properties

### Current

Holds the current `DateTimeProvider`. You can also set a different `DateTimeProvider`. The default provider is `DefaultDateTimeProvider`.

```csharp
DateTimeProvider Current { get; set; } = new DefaultDateTimeProvider()
```

**Remarks**

This property should be used whenever you need to get the current `DateTimeOffset`.

**Example**

The example below sets the order date of the customer order to the current date and time.

Code Sample:

```csharp
private void SetCustomerOrderInfo(CustomerOrder customerOrder)
{
  if (customerOrder.PlacedByUserProfile == null)
  {
      customerOrder.PlacedByUserProfile = SiteContext.Current.UserProfile;
      customerOrder.PlacedByUserName = SiteContext.Current.UserProfile.UserName;
  }
     
  customerOrder.OrderDate = DateTimeProvider.Current.Now;
     
  if (customerOrder.RequestedShipDate == null)
  {
      customerOrder.RequestedShipDate = customerOrder.OrderDate;
  }
     
  if (customerOrder.CurrencyId == null && SiteContext.Current.CurrencyDto != null)
  {
      this.customerOrderUtilities.SetCurrency(customerOrder, SiteContext.Current.CurrencyDto.Id);
  }
}
```

**Now**

Gets the now.

```csharp
abstract DateTimeOffset Now { get; }
```

## Methods

### ResetToDefault()

Resets the current DateTimeProvider to the default, which is `DefaultDateTimeProvider`.

```csharp
static void ResetToDefault()
```
