# $addDate

`$addDate` operator lets you **modify** date and datetimes. You can use this in any [<mark style="color:blue;">**Expression Object**</mark>](https://docs.cosmocloud.io/flow-builder/cql-cosmocloud-query-language/building-expressions).

This operator can work on both **epoch timestamps** as well as **datetime** objects.

## Syntax

```json
{
    "$addDate": {
        "startDate": <date_like_obj>,
        "unit": "DAY" | "WEEKS"
        "amount": <change_difference>
    }
}
```

### Properties

| Field                 | Description                                                                                                                                                                                                                                                                                                                                                                                                                        | Required |
| --------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- |
| \<date\_like\_obj>    | <p>The <code>\<date\_like\_obj></code> expression can be any valid <a href=""><mark style="color:blue;"><strong>expression</strong></mark></a> as long as it resolves to a <strong>epoch timestamp</strong> (seconds or milliseconds), or to <strong>datetime</strong> objects.</p><p></p><p>It can also be a <strong>Magical Autocomplete</strong>.<br><br>The epoch timestamp can be both in seconds as well as millisecond.</p> | true     |
| unit                  | It can be either **DAY** or **WEEKS**                                                                                                                                                                                                                                                                                                                                                                                              | true     |
| \<change\_difference> | <p>The <code>\<change\_difference></code> expression can be any valid <a href=""><mark style="color:blue;"><strong>expression</strong></mark></a> as long as it resolves to a number.</p><p></p><p>The value by which you want to add or substract days/weeks from the <code>startDate</code>.</p>                                                                                                                                 | true     |

### Returns

`integer` - If the **startDate** is of type **integer** (both milliseconds and seconds)

`datetime` - If the **startDate** is of type **datetime**

## Examples

### Timestamp in epoch (seconds)

```json
{
    "$addDate": {
        "startDate": 1709796918,
        "unit": "DAY",
        "amount": 1
    }
}
```

The above expression returns **1709883318**.

### Timestamp in epoch (milliseconds)

```json
{
    "$addDate": {
        "startDate": 1709796918000,
        "unit": "DAY",
        "amount": 1
    }
}
```

The above expression returns **1709883318000**.

### With Magical Autocomplete

Let's say we have declared a variable `temp` in our API flow, which has a value of **6** currently.

```json
{
    "$addDate": {
        "startDate": datetime(2024, 03, 20),
        "unit": "WEEK",
        "amount": 1
    }
}
```

The above expression would resolve to a result of **datetime(2024, 03, 27)**.
