> ## 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.

# Totimestamp

# \$toTimestamp

The `$toTimestamp` operator converts a date object to a timestamp.

## Input

* An array containing a date object and an optional granularity parameter (0 for seconds, 3 for milliseconds, 6 for microseconds, 9 for nanoseconds)

## Output

* The timestamp representation of the date object

## Examples

### Convert Date to Unix Timestamp (Seconds)

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

Result: `1673777400` (seconds since Unix epoch)

### Convert Date to Milliseconds

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

Result: `1673777400000` (milliseconds since Unix epoch)

### Field Value

```json theme={null}
{
  "$toTimestamp": [
    {
      "$input": "date_value"
    },
    0
  ]
}
```

Result: The timestamp in seconds since Unix epoch for the date\_value field
