Date expressions (also called dynamic date parameters) let you define a date or time relative to the current date, so a query can retrieve data for a moving time range — for example, from the start of the month to today, or for the previous week. The date expression is re-evaluated on every data feed refresh, so the range slides forward automatically instead of being hard-coded.
This article covers:
- Where to use date expressions
- Date formats
- Date expression syntax
- Date method reference guide
- Examples
- Validating date expressions
Where to use date expressions
Date expressions can be used in the request fields you configure during data feed creation, for example, in the Query URL (including its query string) or in the Query Body for POST requests.
A date parameter in a query can also be set to a hard-coded value, for example 2025-12-12. Use a date expression instead whenever the range should move with the current date.
Date formats
Date formats refer to how a date is represented as text. For example, December 1, 2025 can be represented as:
-
December 1, 2025(formatMMMM d, yyyy) -
01-12-2025(formatdd-MM-yyyy) -
1764547200(Unix time — the number of seconds elapsed since midnight January 1, 1970 UTC)
Date expression syntax
Date expressions start with the keyword date, followed by a chain of methods in a fixed order, all contained in curly braces. Square brackets mark optional parts (the brackets aren’t part of the syntax), and ... means a part can repeat:
{date[.setMethod][.dateSetting ...][.manipulationMethod ...][.dateShortcut][.formatMethod]}
The keyword date is required, and may be followed by, in this order:
- at most one set method
- any number of date settings
- any number of manipulation methods
- at most one date shortcut
- at most one format method
Date methods return values in EST by default. Note that this is fixed EST (UTC−5) year-round; it does not observe daylight saving time. During daylight saving, Eastern local time is UTC−4, so default date/time values run one hour behind Eastern wall-clock time, and day boundaries (today, yesterday, startOfWeek, etc.) change at 1:00 AM local Eastern rather than midnight. For Eastern local time that observes daylight saving, use tz("America/New_York"). tz() accepts full region time zone IDs and short codes.
Method names are case-sensitive: Use last30Days, not last30days.
Date expression syntax examples:
-
{date.addMonths(-1).format('yyyyMMdd')}— manipulation method + format method. One month ago, formatted asyyyyMMdd. -
{date.firstDOW("mon").addWeeks(-1).startOfWeek.format()}— date setting + manipulation method + date shortcut + format method. The start of the previous week, where weeks begin on Monday. -
{date.today}— date shortcut only. Today's date in the defaultyyyy-MM-ddformat.
Date method reference guide
date (required keyword)
| Method | Description | Example |
date |
Required keyword. Sets the date/time to the current date/time. | date |
Set methods (zero or one per expression)
Set methods set the date/time to a specific value.
| Method | Description | Example |
set(dateString) |
Sets the date/time to the value specified by dateString in yyyy-MM-dd format. Time is set to 00:00:00 EST. |
set("2026-01-31") |
set(dateString, dateFormat) |
Sets the date to dateString interpreted using dateFormat. |
set("310125","ddMMyy") |
start() |
Equivalent to set("00:00:00","hh:mm:ss"). |
start() |
end() |
Equivalent to set("23:59:59","hh:mm:ss"). |
end() |
Date settings (zero or more per expression)
Date settings define the time zone, first day of the week, and first month of the year.
| Method | Description | Example |
tz(tzCode) |
Sets the date/time to the specified time zone. | tz("est") |
firstDOW(dayOfWeek) |
Sets the first day of the week to one of sun, mon, tue, wed, thu, fri, sat. Used with startOfWeek and endOfWeek. Default is Sunday. |
firstDOW("mon") |
firstMOY(month) |
Sets the first month of the year to one of jan through dec. Used with startOfYear and endOfYear. Default is January. |
firstMOY("apr") |
Date manipulation methods (zero or more per expression)
Date manipulation methods add or subtract units of time. Use negative numbers to subtract.
Note: To add or subtract days, use add(n).
| Method | Description | Examples |
add(integer) |
Adds n days. |
add(-7), add(14)
|
addMinutes(integer) |
Adds n minutes. |
addMinutes(30), addMinutes(-15)
|
addHours(integer) |
Adds n hours. |
addHours(-1), addHours(5)
|
addWeeks(integer) |
Adds n weeks. |
addWeeks(4), addWeeks(-26)
|
addMonths(integer) |
Adds n months. |
addMonths(-1), addMonths(5)
|
addQuarters(integer) |
Adds n quarters. |
addQuarters(1), addQuarters(-3)
|
addYears(integer) |
Adds n years. |
addYears(-2), addYears(1)
|
Date shortcuts (zero or one per expression)
Date shortcuts set the date/time and return it in yyyy-MM-dd format by default.
Shortcuts behave in two distinct ways:
-
today,yesterday,last7Days,last30Days, andlast60Daysare absolute: they reset the date relative to the current date/time, discarding any set or manipulation methods earlier in the chain. For example,{date.set("2026-01-31").today}returns today's date, not January 31. - The
startOf...andendOf...shortcuts are relative: they adjust whatever date the chain has produced so far. This is why{date.addMonths(-1).startOfMonth}returns the start of the previous month.
| Method | Description |
today |
The current date/time (EST). |
yesterday |
Yesterday, current time (EST). |
last7Days |
7 days ago, current time (EST). |
last30Days |
30 days ago, current time (EST). |
last60Days |
60 days ago, current time (EST). |
startOfWeek / endOfWeek
|
Start/end of the current week, where the first day of the week is set by firstDOW. |
startOfMonth / endOfMonth
|
Start/end of the current month. |
startOfQuarter / endOfQuarter
|
Start/end of the current quarter, where the first month of the year is set by firstMOY. |
startOfYear / endOfYear
|
Start/end of the current year, where the first month of the year is set by firstMOY. |
Format methods (zero or one per expression)
A format method is required when:
- no date shortcut is used in the expression, or
- a date shortcut is used but you need a format other than the default
yyyy-MM-dd.
If an expression doesn’t contain a date shortcut or a format method, it does not resolve to a date. Instead, it renders in the request as an internal object reference which the target API will reject. If you see a string like this in a request, a response, or an error message, add .format() (or a date shortcut) to the end of the expression.
| Method | Description | Example |
format() |
Formats the date as yyyy-MM-dd. |
format() |
format(dateFormat) |
Formats the date using the specified format. |
format("ddMMyyyy"), format("unixtime"), format("epochTime")
|
Examples
From the start of the current quarter to today at noon (CST), default format. Retrieves data from the first day of the current quarter at 00:00:00 to the current date at 12:00:00:
https://www.webservice.com/data?start-date={date.tz("cst").startOfQuarter}&end-date={date.set("12:00:00","HH:mm:ss").today}
From the start of the previous year to now, in Unix time:
https://www.webservice.com/data?start-date={date.addYears(-1).startOfYear.format("unixtime")}&end-date={date.today.format("unixtime")}
Unix time in milliseconds. Some web service APIs require date/times in Unix time as milliseconds; append 000 to the unix time parameter:
https://www.webservice.com/data?start-date={date.add(-7).format('unixtime')}000&end-date={date.today.format("unixtime")}000
From the start of the fiscal year to today, where the fiscal year starts April 1st (uses firstMOY):
https://www.webservice.com/data?start-date={date.firstMOY("apr").startOfYear.format()}&end-date={date.today}
The previous week, where the week starts on Monday (uses firstDOW):
https://www.webservice.com/data?start-date={date.firstDOW("mon").addWeeks(-1).startOfWeek.format()}&end-date={date.firstDOW("mon").addWeeks(-1).endOfWeek.format()}
Validating date expressions
To validate the results returned by a date expression, create a REST/URL data feed in PowerMetrics (you don't need to save it):
- Click the + button beside Data Feeds in the left navigation sidebar.
- Click Select data.
- On the Where is your data? page, select REST/URL.
- On the Configure data service page, set Query URL to:
https://httpbin.org/get?<fromDate>&<toDate>where<fromDate>and<toDate>are the date parameters from your query.
For example, if the date parameters arefrom={date.addHours(-15).format("yyyy-MM-dd'T'HH:mm:ssZ")}andto={date.today.format()}, set the Query URL to:https://httpbin.org/get?from={date.addHours(-15).format("yyyy-MM-dd'T'HH:mm:ssZ")}&to={date.today.format()} - Set Data Format to JSON and Method to GET.
- Click Get data. The resolved date values are listed under the
argsobject in the response. - Click Cancel to exit.