> For the complete documentation index, see [llms.txt](https://dev.ubidots.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dev.ubidots.com/synthetic-variables/expressions/date-range.md).

# Date range

Ubidots lets you build new variables from time-series data over a date range. For example, you can calculate the mean, sum, or median per hour using a synthetic variable based on your sensor inputs.

Below are the most common date range functions.

|       Function      |                                     Description                                    |
| :-----------------: | :--------------------------------------------------------------------------------: |
|  $$max(x, range)$$  |      Returns the maximum value of the variable x in the specified date range.      |
|  $$min(x, range)$$  |      Returns the minimum value of the variable x in the specified date range.      |
|  $$mean(x, range)$$ |        Returns the mean value of the variable x in the specified date range.       |
|  $$std(x, range)$$  |    Returns the standard deviation of the variable x in the specified date range.   |
| $$count(x, range)$$ |  Returns the number of dots stored in the variable x for the specified date range. |
|  $$last(x, range)$$ |  Returns the last value of the time-series variable x in the specified date range. |
| $$first(x, range)$$ | Returns the first value of the time-series variable x in the specified date range. |
|  $$sum(x, range)$$  |  Returns the sum of the dots stored in the variable x in the specified date range. |

Date range functions use the following syntax:

***`aggregation_method(<variable>, <range>, <position>, <offset>)`***

| Parameters |                                                                                                                                                                                                   Description                                                                                                                                                                                                  |                                                                                                                                                                                                                      Value                                                                                                                                                                                                                     | Mandatory |
| :--------: | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :-------: |
|  Variable  |                                                           Represents the measurements of a sensor as a [time series](https://docs.ubidots.com/v1.6/reference/time-series) of data points that vary over time. Also known as ["dots"](https://help.ubidots.com/en/articles/636672-plans-billing-what-are-dots), it is identified by a variable label.                                                           |                                                                                                                                                                                                                 Variable label                                                                                                                                                                                                                 |    YES    |
|    Range   | <p>The time window in which the function is computed.</p><p><strong>Note:</strong> Set the selected range so it evenly divides the next range. For example, if you use minutes ("T"), the number <strong>n</strong> must evenly divide an hour ("H"). Available minute values are 1, 2, 3, 4, 5, 6, 10, 12, 15, 20, and 30. Other values may produce unexpected results. The same applies to other ranges.</p> | <p>Available data ranges:</p><p>This is a <strong>positive integer</strong> that represents the number of observations used for each window, or a <strong>time range</strong> specified as follows:</p><p><strong>"nT"</strong>: Every n minutes</p><p><strong>"nH"</strong>: Every n hours</p><p><strong>"nD"</strong>: Every n days</p><p><strong>"W"</strong>: Every end of the week</p><p><strong>"M"</strong>: Every end of the month</p> |    YES    |
|  Position  |                                                                                                                                                        Indicates whether the output value is timestamped at the start or at the end of the time series.                                                                                                                                                        |                                                                                                                                                                                                   `position = "start"` or `position = "end"`                                                                                                                                                                                                   |     NO    |
|   Offset   |                                                                                                                       Sets the hour at which the synthetic variable engine starts computing the variable. This value represents the number of hours after midnight. By default, it is 0.                                                                                                                       |                                                                                                                                                                                                          Any integer between 1 and 23                                                                                                                                                                                                          |     NO    |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://dev.ubidots.com/synthetic-variables/expressions/date-range.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
