[SalesForce] SOQL query on date field WHERE by year

I have a custom object having a Date field Card__Date__c

I need to perform a soql query on the custom object where Card__Date__c in 2017

So my query looks like

List<TimeCard__c> tcList = [select id, Name from TimeCard__c where Card__Date__c = 2018 ];

This one is wrong. Not sure about where cause.

How do I perform this – where the year for that date field is in a fixed year ?

Best Answer

Substitute the year with the one you want to get records for:

Documentation here

   SELECT CreatedDate, Name
    FROM Account
    WHERE CALENDAR_YEAR(CreatedDate) = 2018