+ Start a Discussion
Hari nadh babu Eluru 7Hari nadh babu Eluru 7 

Getting Error in the above code

Date myOldDate = Date.newInstance(2021, 1, 1);
Date myTodayDate = date.today();
List<Student__c>studentList = new List <Student__c>();
studentList = [SELECT Student_Id__c, Name, Joining_Date__c FROM Student__c
              WHERE Joining_Date__c >: myOldDate AND Joining_Date__c :<= myTodayDate];
In this above code i had getting this below error
Error Message
The error is appeared at in "studentList =" on here at in equalto symbol. Please resolve my problem. Thank you !
Best Answer chosen by Hari nadh babu Eluru 7
Suraj Tripathi 47Suraj Tripathi 47
Here's why you are getting the error, actually you have mistakenly used colon at the wrong place, so here's the little change I have made to your code:

Date myOldDate = Date.newInstance(2021, 1, 1);
Date myTodayDate = date.today();
List<Student__c>studentList = new List <Student__c>();
studentList = [SELECT Student_Id__c, Name, Joining_Date__c FROM Student__c
              WHERE Joining_Date__c > :myOldDate AND Joining_Date__c <= :myTodayDate]; // Here's the error, you have to use the colon after the equals
 
I hope you find the above solution helpful. If it does, please mark it as Best Answer.
Thanks and Regards,
Suraj

All Answers

Suraj Tripathi 47Suraj Tripathi 47
Here's why you are getting the error, actually you have mistakenly used colon at the wrong place, so here's the little change I have made to your code:

Date myOldDate = Date.newInstance(2021, 1, 1);
Date myTodayDate = date.today();
List<Student__c>studentList = new List <Student__c>();
studentList = [SELECT Student_Id__c, Name, Joining_Date__c FROM Student__c
              WHERE Joining_Date__c > :myOldDate AND Joining_Date__c <= :myTodayDate]; // Here's the error, you have to use the colon after the equals
 
I hope you find the above solution helpful. If it does, please mark it as Best Answer.
Thanks and Regards,
Suraj
This was selected as the best answer
mukesh guptamukesh gupta
Hi HARI,

YOUR CODE WAS CORRECT , BUT ONLY ONE MISTAKE,   use <= :  INSTED of  :<=


Please use below code
Date myOldDate = Date.newInstance(2021, 1, 1);
Date myTodayDate = date.today();
List<Student__c>studentList = new List <Student__c>();
studentList = [SELECT Student_Id__c, Name, Joining_Date__c FROM Student__c
              WHERE Joining_Date__c >: myOldDate AND Joining_Date__c <= :myTodayDate];

if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh

 
ravi soniravi soni
hi hari,
your code is looking good but you committed a very minor mistake. you should have add colon(:) after (=).
just code and paste below code your issue will be resolved.
Date myOldDate = Date.newInstance(2021, 1, 1);
Date myTodayDate = date.today();
List<Student__c>studentList = new List <Student__c>();
studentList = [SELECT Student_Id__c, Name, Joining_Date__c FROM Student__c
              WHERE Joining_Date__c >: myOldDate AND Joining_Date__c <=: myTodayDate];

let me know by marking it as best answer.
Thank you
 
ravi soniravi soni
Hi hari,
did you try my solution. if it works then mark it as best answer.
thank you