I have a custom object having a Date field Expense__Date__c
I need to perform a soql query on the custom object where Expense__Date__c = THIS_MONTH
So my query looks like
List<CustomObj__c> list = [select Name from CustomObj__c where Expense__Date__c = THIS_MONTH];
But it gives an error Unexpected token : THIS_MONTH
When I try to do something like this
List<CustomObj__c> list = [select Name from CustomObj__c where Expense__Date__c.month() = :Date.Today().Month()];
It gives in error unexpected token ')'
How do I perform this filter – where the month for that date field is current month, in a soql query?
Thanks
Best Answer
Confirming @Eric, your query
is validated by the following:
I tried out a version of your query myself, and it worked fine.
Though this is besides the point (the Date Literals work), there is always the option of "rolling your own" by something like the following: