# Create Future And Past Dates From Today

JavaScript's built-in [`Date`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) object can be frustrating to work with at times. It does, however, lend itself nicely to some date math. You have to familiarize yourself with some of the API and then it is a matter of addition and subtraction.

Here is today:

```javascript
const today = new Date();
// Tue Dec 01 2020 ...
```

Let's make a copy of today and send it 30 days into the future:

```javascript
const future = new Date(today);
future.setDate(future.getDate() + 30);
future
// Thu Dec 31 2020 ...
```

Or we could jump back a few years:

```javascript
const past = new Date(today);
past.setFullYear(past.getFullYear() - 4);
past
// Thu Dec 01 2016 ...
```

[source](https://stackoverflow.com/questions/7908098/javascript-set-date-30-days-from-now/7908122#7908122)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ploegert.gitbook.io/til/programmy/javascript/create-future-and-past-dates-from-today.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
