---
title: DateTime
slug: cms-12/docs/datetime
createdAt: 2026-08-10T15:55:59.000Z
---

Use filters to narrow down search results, or use them for database-like queries.

Use the `Filter` method to filter `DateTime` and nullable `DateTime` fields in several ways. The following list shows use cases and examples illustrating the available methods.

:::hint{type="info"}
**Note**
If you cache the search results using the [built in caching functionality](docId\:ZN-Q38zT-7OGJyYzlkzf3), you probably do not want to use `DateTime.Now` in your filters, because the cache key will differ for each search. In those cases, instead, normalize the `DateTime` value to the closest minute or, at the very least, second.
:::

## Exists

Use the `Exists` method to search for documents where a `DateTime` field has a value. The following search finds blog posts with a `PublishDate` property with a value. The following code is similar to the LINQ query `Where(x => x.PublishDate.HasValue)`.

```csharp
var searchQuery = client.Search<BlogPost>()
  .Filter(x => x.PublishDate.Exists());
```

Use the following code to negate it with an exclamation point (!) to find blog posts with no publish date.

```csharp
var searchQuery = client.Search<BlogPost>()
  .Filter(x => !x.PublishDate.Exists());
```

## Exact match

For exact matching, use the `Match` method. The following search matches blog posts published exactly at 2010-01-01 00:00. It does not match those published 2009-12-31, 2010-01-01 01:00, or 2010-01-02. The LINQ equivalent is `Where(x => x.PublishDate == new DateTime(2010, 1, 1))`.

```csharp
var searchQuery = client.Search<BlogPost>()
  .Filter(x => x.PublishDate.Match(new DateTime(2010, 1, 1)));
```

## Match by range

To find documents with a `DateTime` field whose value is within a given range, use the `InRange` method. The following search matches blog posts that were published between 2010-01-01 00:00 and 2010-01-02 00:00. An equivalent in LINQ is `Where(x => x.PublishDate >= new DateTime(2010, 1, 1) && x.PublishDate <= new DateTime(2010, 1, 2))`.

```csharp
var searchQuery = client.Search<BlogPost>()
  .Filter(x => x.PublishDate.InRange(new DateTime(2010, 1, 1), new DateTime(2010, 1, 2)));
```

For convenience, the .NET API also features the `GreaterThan`, `LessThan`, `Before`, and `After` methods that make range filtering easier for `DateTime` fields.
