# Date Occurring Rule

Learn how to apply conditional formatting by comparing the values entered in date format in the cells or a range of cells using DsExcel.

## Content

The date occurring rule in conditional formatting feature compares the values entered in date format in the cells or a range of cells. This rule can be added using the [DateOperator property](/document-solutions/dot-net-excel-api/api/online/DS.Documents.Excel/GrapeCity.Documents.Excel.IFormatCondition.DateOperator.html) of the [IFormatCondition interface](/document-solutions/dot-net-excel-api/api/online/DS.Documents.Excel/GrapeCity.Documents.Excel.IFormatCondition.html).
Refer to the following example code to add date occurring rule to a range of cells in a worksheet.

```csharp
// Adding Date occuring rules
IFormatCondition condition = worksheet.Range["A1:A4"].FormatConditions.Add(FormatConditionType.TimePeriod) as IFormatCondition;
condition.DateOperator = TimePeriods.Yesterday;
condition.Interior.Color = Color.FromArgb(128, 0, 128);

DateTime now = DateTime.Today;
worksheet.Range["A1"].Value = now.AddDays(-2);
worksheet.Range["A2"].Value = now.AddDays(-1);
worksheet.Range["A3"].Value = now;
worksheet.Range["A4"].Value = now.AddDays(1);
```