> ## Documentation Index
> Fetch the complete documentation index at: https://docs.metrics-man.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Datediff

# \$dateDiff

The `$dateDiff` operator calculates the difference between two dates in specified units.

## Input

* An array containing two date objects and a string representing the unit of measurement ("days", "hours", "minutes", "seconds", "weeks", "months", "years")

## Output

* The difference between the two dates in the specified unit

## Examples

### Calculate Days Difference

```json theme={null}
{
  "$dateDiff": [
    {
      "$toDate": ["2023-01-20T10:30:00Z"]
    },
    {
      "$toDate": ["2023-01-15T10:30:00Z"]
    },
    "days"
  ]
}
```

Result: `5`

### Calculate Hours Difference

```json theme={null}
{
  "$dateDiff": [
    {
      "$toDate": ["2023-01-15T15:30:00Z"]
    },
    {
      "$toDate": ["2023-01-15T10:30:00Z"]
    },
    "hours"
  ]
}
```

Result: `5`

### Calculate Field Values Difference

```json theme={null}
{
  "$dateDiff": [
    {
      "$input": "end_date"
    },
    {
      "$input": "start_date"
    },
    "months"
  ]
}
```

Result: The difference in months between the end\_date and start\_date fields
