Date Ranges
Overview
In this section you can find information on how to handle the construction of complex date expressions.
More specifically how to construct the start or end date of a period and use it for displaying or for
querying data service.
Together with the Predefined Manifest Parameters TODAY_ISO
and NOW_ISO
cards provide a helper for handling date ranges.
Date Range
Inside the card manifest you can use the global functions dateRange.start
and
dateRange.end
to create the start or the end date of a date range.
For example, a date range like 'last 5 years' can be used inside an expression binding like this:
{= dateRange.start("lastYears", 5)}
.
dateRange.start(type, value?) : UniversalDate
dateRange.end(type, value?) : UniversalDate
Param | Type | Description | Since |
---|---|---|---|
type | string | A valid date range type like 'lastYears'. For full list see the table below. | 1.73 |
value | int | How many years, days, months, etc. to be the range. If range is 'lastYears' this parameter describes how many years. | 1.73 |
Returns | 1.73 | ||
UniversalDate | The start/end date of the range. UniversalDate is convertable to Date or string. | 1.73 |
Supported date ranges
type |
Description | value |
---|---|---|
lastDays | Number of days before the current day | Number of days |
yesterday | Start and end of yesterday's date | |
today | Start and end of today's date | |
codesample | Start and end of codesample's date | |
nextDays | Number of days after the current day | Number of days |
lastWeeks | Number of weeks before the current week | Number of weeks |
lastWeek | Start and end of last week | |
currentWeek | Start and end of the current week | |
nextWeek | Start and end of next week's | |
nextWeeks | Number of weeks after the current week | Number of weeks |
lastMonths | Number of months before the current month | Number of months |
lastMonth | Start and end of last month | |
currentMonth | Start and end of current month | |
nextMonth | Start and end of next month | |
nextMonths | Number of months after the current month | Number of months |
lastQuarters | Start and end of the number of quarters before the current quarter | Number of quarters |
lastQuarter | Start and end of last quarter | |
currentQuarter | Start and end of current quarter | |
nextQuarter | Start and end of next quarter | |
nextQuarters | Start and end of number of quarters after the current quarter | Number of quarters |
quarter | Start and end of the specified quarter of the current year | Which quarter |
lastYears | Number of years before the current year | Number of years |
lastYear | Start and end of last year | |
currentYear | Start and end of current year | |
nextYear | Start and end of next year | |
nextYears | Number of years after the current year | Number of years |
yearToDate | Range between the first day of the current year and today |
Examples
Expression | Result if today is 2019-11-01 |
---|---|
{= dateRange.start('lastYears', 5)} |
2014-01-01T00:00:00 |
{= dateRange.end('lastYears', 5)} |
2018-12-31T23:59:59 |
{= dateRange.start('yesterday')} |
2019-10-31T00:00:00 |
{= dateRange.end('nextQuarter')} |
2020-03-31T23:59:59 |
Date range in title:
{ "header": { "title": "Expectations for next 6 months", "subTitle": "Until {= format.dateTime(dateRange.end('nextMonths', 6), {pattern: 'MMMM, y'})}" } }
Date range used in odata request:
{ "data": { "request": { "url": "https/services.odata.org/V3/Northwind/Northwind.svc/Orders", "parameters": { "$format": "json", "$top": 5, "$orderby": "Freight desc", "$filter": "OrderDate ge datetime'{= format.dateTime(dateRange.start('lastYears', 30), {pattern: 'yyyy-MM-ddTHH:mm:ss'})}'" } }, "path": "/value/" } }Try it Out