SOQL Date Functions
SOQL supports some date functions which can be applied on Date and Datetime fields value in the WHERE Clause before comparing.
Here are a few commonly used Date Functions:
| Function Name | Description | Example |
|---|---|---|
| CALENDAR_MONTH | To find the Integer value of the current month. 1 for January, 12 for December |
|
| CALENDAR_YEAR | To find the year of a date field. |
|
| DAY_IN_WEEK | To find the day at which the date points. 1 for Monday, 7 for Sunday |
|
These functions can not be used in Select Clauses while returning field values, unless used in a special Group BY Clauses which we see later.
For instance, the following query throws a syntax error:
SELECT Id, CALENDAR_YEAR(BirthDate)
FROM Contact