function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion


I have an object with a datetime field. I want to select all records from this object where the datetime's month and year value, equals the current month and year.

So it might look like

SELECT Name FROM myObj__c WHERE date_time.getMonth() = currentMonth AND date_time.getYear() = currentYear

Any help is much appreciated!
I think you want to use some of the SOQL supported Date Literals as detailed here:

You can try THIS_MONTH and THIS_YEAR in your Where clause.