Date and time functions
Date and time functions are used to perform date and time operations on values within Profile Query Language (PQL). More information about other PQL functions can be found in the Profile Query Language overview.
Current month
The currentMonth
function returns the current month as an integer.
Format
currentMonth()
Example
The following PQL query checks if the person’s birth month is the current month.
person.birthMonth = currentMonth()
Get month
The getMonth
function returns the month, as an integer, based on a given timestamp.
Format
{TIMESTAMP}.getMonth()
Example
The following PQL query checks if the person’s birth month is in June.
person.birthdate.getMonth() = 6
Current year
The currentYear
function returns the current year as an integer.
Format
currentYear()
Example
The following PQL query checks if the product was sold in the current year.
product.saleYear = currentYear()
Get year
The getYear
function returns the year, as an integer, based on a given timestamp.
Format
{TIMESTAMP}.getYear()
Example
The following PQL query checks if the person’s birth year falls in 1991, 1992, 1993, 1994, or 1995.
person.birthday.getYear() in [1991, 1992, 1993, 1994, 1995]
Current day of month
The currentDayOfMonth
function returns the current day of the month as an integer.
Format
currentDayOfMonth()
Example
The following PQL query checks if the person’s birth day matches the current day of the month.
person.birthDay = currentDayOfMonth()
Get day of month
The getDayOfMonth
function returns the day, as an integer, based on a given timestamp.
Format
{TIMESTAMP}.getDayOfMonth()
Example
The following PQL query checks if the item was sold within the first 15 days of the month.
product.sale.getDayOfMonth() <= 15
Occurs
The occurs
function compares the given timestamp function with a fixed period of time as a boolean.
Format
The occurs
function can be written using any of the following formats:
{TIMESTAMP} occurs {COMPARISON} {INTEGER} {TIME_UNIT} {DIRECTION} {TIME}
{TIMESTAMP} occurs {DIRECTION} {TIME}
{TIMESTAMP} occurs (on) {TIME}
{TIMESTAMP} occurs between {TIME} and {TIME}
{COMPARISON}
>
, >=
, <
, <=
, =
, !=
. More information about the comparison functions can be found in the comparison functions document.{INTEGER}
{TIME_UNIT}
millisecond(s)
, second(s)
, minute(s)
, hour(s)
, day(s)
, week(s)
, month(s)
, year(s)
, decade(s)
, century
, centuries
, millennium
, millennia
.{DIRECTION}
before
, after
, from
.{TIME}
today
, now
, yesterday
, tomorrow
), a relative time unit (one of this
, last
, or next
followed by a time unit), or a timestamp attribute.on
is optional. It is there to improve readability for some combinations, such as timestamp occurs on date(2019,12,31)
.Example
The following PQL query checks if the item was sold last week.
product.saleDate occurs last week
The following PQL query checks if an item was sold between January 8th, 2015 and July 1st, 2017.
product.saleDate occurs between date(2015, 1, 8) and date(2017, 7, 1)
Now
now
is a reserved word that represents the timestamp of the PQL execution.
Example
The following PQL query checks if an item was sold exactly three hours before.
product.saleDate occurs = 3 hours before now
Today
today
is a reserved word that represents the timestamp of the start of the day of the PQL execution.
Example
The following PQL query checks if a person’s birthday was three days ago.
person.birthday occurs = 3 days before today
Next steps
Now that you have learned about date and time functions, you can use them within your PQL queries. For more information about other PQL functions, please read the Profile Query Language overview.