+ Start a Discussion
Hari nadh babu EluruHari nadh babu Eluru 

SOQL Dates between

Write an SOQL Query to fetch students who joined in between january 1st 2021 to till today date. I want only SOQL Query to execute without list or set
Best Answer chosen by Hari nadh babu Eluru
Suraj Tripathi 47Suraj Tripathi 47
Hi Hari ,

you can take the reference of below code . Here first we create instance of  january 1st 2021 and todays date and then we use below query to fetch records of student who join in betweeen these day .

Here Student__c is Sobject and JoinedDate__c is field of Student __c SObject

Date startDate = Date.newInstance(2021, 1, 1);
Date TodayDate = system.today();

[SELECT Id,Name FROM Student__c WHERE JoinedDate__c >: startDate  AND JoinedDate__c <=: TodayDate ];

If you find your Solution then mark this as the best answer.

Thank you!
Suraj Tripathi