Date Literal


Date Literal


The following date literal functions can be used to filter date fields using relative intervals. Note that while the <, >, and = operators are supported for these functions, <= and >= are not.

TODAY()

The current day.

SELECT * FROM MyTable WHERE MyDateField = TODAY()

YESTERDAY()

The previous day.

SELECT * FROM MyTable WHERE MyDateField = YESTERDAY()

TOMORROW()

The following day.

SELECT * FROM MyTable WHERE MyDateField = TOMORROW()

LAST_WEEK()

Every day in the preceding week.

SELECT * FROM MyTable WHERE MyDateField = LAST_WEEK()

THIS_WEEK()

Every day in the current week.

SELECT * FROM MyTable WHERE MyDateField = THIS_WEEK()

NEXT_WEEK()

Every day in the following week.

SELECT * FROM MyTable WHERE MyDateField = NEXT_WEEK()

Also available:

  • LAST/THIS/NEXT MONTH
  • LAST/THIS/NEXT QUARTER
  • LAST/THIS/NEXT YEAR

LAST_N_DAYS(n)

The previous n days, excluding the current day.

SELECT * FROM MyTable WHERE MyDateField = LAST_N_DAYS(3)

NEXT_N_DAYS(n)

The following n days, including the current day.

SELECT * FROM MyTable WHERE MyDateField = NEXT_N_DAYS(3)

Also available:

  • LAST/NEXT_90_DAYS

LAST_N_WEEKS(n)

Every day in every week, starting n weeks before current week, and ending in the previous week.

SELECT * FROM MyTable WHERE MyDateField = LAST_N_WEEKS(3)

NEXT_N_WEEKS(n)

Every day in every week, starting the following week, and ending n weeks in the future.

SELECT * FROM MyTable WHERE MyDateField = NEXT_N_WEEKS(3) **Also available:** - LAST/NEXT_N_MONTHS(n) - LAST/NEXT_N_QUARTERS(n) - LAST/NEXT_N_YEARS(n)