Date

The best example of a Date attribute is createdAt. As Dates have different formats, we molded the filters to provide you with as much flexibility as possible.

Field type: Date
Filters: exact (=), date, year, quarter, month, week, day, hour, minute, second, isnull

exact
Filters for an exact match of the Date. (ISO Date-Time Format)

GET https://industrial.api.ubidots.com/api/v2.0/devices/?createdAt=2020-05-27T13:29:26.533156Z

//Returns Array 'results' with device createdAt exactly the date provided
{
    "count": 1,
    "next": null,
    "previous": null,
    "results": [
        {
            "createdAt": "2020-05-27T13:29:26.533156Z",
            ...
        }
    ]
}

date
Filters for Dates matching a date (without time reference).

GET https://industrial.api.ubidots.com/api/v2.0/devices/?createdAt__date=2020-05-27

//Returns Array 'results' with Date matching Date provided in query
{
    "count": 1,
    "next": null,
    "previous": null,
    "results": [
        {
            "createdAt": "2020-05-27T13:29:26.533156Z",
            ...
        }
    ]
}

👍

Feature

A Computer treats the Date as a number, hence you can combine Number filters on the Date. Crazy, right? Let's see an example:

date__<number_filter>
As all Dates are treated as a number it's possible to combine Number filters on the dates, i.e. it's possible to filter for a date greater than which means (later in time than).

GET https://industrial.api.ubidots.com/api/v2.0/devices/?createdAt__date__gt=2020-05-20

//Returns Array 'results' with all devices created after May 20th 2020
{
    "count": 3,
    "next": null,
    "previous": null,
    "results": [
        {
            "createdAt": "2020-05-27T13:29:26.533156Z",
            ...
        },
        {
            "createdAt": "2020-05-24T18:39:57.665938Z",
            ...
        },
        {
            "createdAt": "2020-05-24T15:40:08.339581Z",
            ...
        }
    ]
}

year / quarter / month / week / day / hour / minute / second
Dates can be filtered by any of the above mentioned time frames. Let's see some examples:

//Filtering by quarter
GET https://industrial.api.ubidots.com/api/v2.0/devices/?createdAt__quarter=1

//Returns Array 'results' with devices created during the first quarter
{
    "count": 2,
    "next": null,
    "previous": null,
    "results": [
        {
            "createdAt": "2020-03-05T14:50:30.743038Z",
            ...
        },
        {
            "createdAt": "2020-03-03T14:36:30.409860Z",
            ...
        }
    ]
}

//Filtering by devices created later than 
GET https://industrial.api.ubidots.com/api/v2.0/devices/?createdAt__hour__gte=15&fields=createdAt

//Returns Array 'results' with all devices created later than 15:00 (3:00pm) on any date
{
    "count": 2,
    "next": null,
    "previous": null,
    "results": [
        {
            "createdAt": "2020-05-24T18:39:57.665938Z",
          ...
        },
        {
            "createdAt": "2020-05-24T15:40:08.339581Z",
          ...
        }
    ]
}

//Filtering by devices created between in range of dates
GET https://industrial.api.ubidots.com/api/v2.0/devices/?createdAt__day__range=20,25

//Returns Array 'results' with devices created between the 20th and the 25th (of any month or year)
{
    "count": 2,
    "next": null,
    "previous": null,
    "results": [
        {
            "createdAt": "2020-05-24T18:39:57.665938Z",
            ...
        },
        {
            "createdAt": "2020-05-24T15:40:08.339581Z",
            ...
        }
    ]
}

🚧

Attention

Please pay attention to the fact that the time frames, e.g. month, day, hour are all written in singular. In other words days__range is wrong, day__range is correct.

The __isnull filter can be applied to a Dates as described in the Boolean section.