Skip to main content

Expression functions

Log in to add to favourites

Expression Functions are built-in functions that can be used in search queries in place of static values in your where operators. The functions generate a value when they are executed on the server by the API.

Expression Functions make it easier for you to run precise filters against properties on your content records. This enables you to retrieve the exact records you want to see with minimal client-side effort, allowing the API to take care of dynamically generating accurate and correctly formatted values.

Date Functions

  • now()
  • startOfDay()
  • endOfDay()
  • startOfWeek()
  • endOfWeek()
  • startOfMonth()
  • endOfMonth()
  • startOfYear()
  • endOfYear()

These functions generate a UTC datetime value at the specific point in time at which they are executed server-side and are accurate to the millisecond. For example, startOfDay() will resolve to the first millisecond of today's date in UTC time; startOfWeek() will resolve to the first millisecond of the Monday of the week in which today's date (in UTC time) falls.

All date functions have 2 overloads; one that will accept a Relative Time Period as a parameter which will offset the datetime value generated by the function, and another that will accept an integer and the date element will be inferred by the element the function operates on.

Examples

now()

List records created prior to the current UTC DateTime.

JSON
{
    "pageIndex": 0,
    "pageSize": 25,
    "where": [
        {
            "field": "sys.version.created",
            "lessThan": "now()"
        }
    ]
}

List records created in the last 24 hours (day element inferred).

JSON
{
    "pageIndex": 0,
    "pageSize": 25,
    "where": [
        {
            "field": "sys.version.created",
            "greaterThanOrEqualTo": "now(-1)"
        }
    ]
}

startOfDay()

List records created since the start of today.

JSON
{
    "pageIndex": 0,
    "pageSize": 25,
    "where": [
        {
            "field": "sys.version.created",
            "greaterThanOrEqualTo": "startOfDay()"
        }
    ]
}

List records created since the start of this day last week.

JSON
{
    "pageIndex": 0,
    "pageSize": 25,
    "where": [
        {
            "field": "sys.version.created",
            "greaterThanOrEqualTo": "startOfDay(-1w)"
        }
    ]
}

endOfDay()

List records created yesterday.

JSON
{
    "pageIndex": 0,
    "pageSize": 25,
    "where": [
        {
            "field": "sys.version.created",
            "greaterThanOrEqualTo": "startOfDay(-1d)"
        },
        {
             "field": "sys.version.created",
            "lessThanOrEqualTo": "endOfDay(-1d)"
        }
    ]
}

startOfWeek()

List Records created prior to the start of the current week.

JSON
{
    "pageIndex": 0,
    "pageSize": 25,
    "where": [
        {
            "field": "sys.version.created",
            "lessThan": "startOfWeek()"
        }
    ]
}

endOfWeek()

List records created last week (week element inferred).

JSON
{
    "pageIndex": 0,
    "pageSize": 25,
    "where": [
        {
            "field": "sys.version.created",
            "greaterThanOrEqualTo": "startOfWeek(-1)"
        },
        {
             "field": "sys.version.created",
            "lessThanOrEqualTo": "endOfWeek(-1)"
        }
    ]
}

startOfMonth()

List records created since the start of the current month.

JSON
{
    "pageIndex": 0,
    "pageSize": 25,
    "where": [
        {
            "field": "sys.version.created",
            "greaterThanOrEqualTo": "startOfMonth()"
        }
    ]
}

endOfMonth()

List records created in this month last year.

JSON
{
    "pageIndex": 0,
    "pageSize": 25,
    "where": [
        {
            "field": "sys.version.created",
            "greaterThanOrEqualTo": "startOfMonth(-1y)"
        },
        {
             "field": "sys.version.created",
            "lessThanOrEqualTo": "endOfMonth(-1y)"
        }
    ]
}

startOfYear()

List records created so far this year.

JSON
{
    "pageIndex": 0,
    "pageSize": 25,
    "where": [
        {
            "field": "sys.version.created",
            "greaterThanOrEqualTo": "startOfYear()"
        }
    ]
}

endOfYear()

List records created last year (year element inferred in "lessThanOrEqualTo" operator).

JSON
{
    "pageIndex": 0,
    "pageSize": 25,
    "where": [
        {
            "field": "sys.version.created",
            "greaterThanOrEqualTo": "startOfYear(-1y)"
        },
        {
             "field": "sys.version.created",
            "lessThanOrEqualTo": "endOfYear(-1)"
        }
    ]
}

Still need help?

If you still need help after reading this article, don't hesitate to reach out to the Contensis community on Slack or raise a support ticket to get help from our team.
New support request