3

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 ?

2 Answers 2

13

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

Documentation here

   SELECT CreatedDate, Name
    FROM Account
    WHERE CALENDAR_YEAR(CreatedDate) = 2018
-4
Date startDate = date.newinstance(2017, 1, 1);
Date endDate = date.newinstance(2017, 12, 31);

List<Account> accList = [select id, name from account where CreatedDate >: startDate and CreatedDate <: endDate];

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .