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.
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()
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
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()
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]
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()
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
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}
Argument | Description |
---|---|
{COMPARISON} |
A comparison operator. Can be any of the following operators: > , >= , < , <= , = , != . More information about the comparison functions can be found in the comparison functions document. |
{INTEGER} |
A non-negative integer. |
{TIME_UNIT} |
A unit of time. Can be any of the following words: millisecond(s) , second(s) , minute(s) , hour(s) , day(s) , week(s) , month(s) , year(s) , decade(s) , century , centuries , millennium , millennia . |
{DIRECTION} |
A preposition describing when to compare the date to. Can be any of the following words: before , after , from . |
{TIME} |
Can be a timestamp literal (today , now , yesterday , tomorrow ), a relative time unit (one of this , last , or next followed by a time unit), or a timestamp attribute. |
Usage of the word 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
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
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
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.