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
Karthik jKarthik j 

soql query not returning result with dynamic variable

Hi all,

I am trying to query all the tasks which are last modified today.
List<Task> taskList= [Select Id,status,LastModifiedDate from Task where LastModifiedDate=TODAY];

the above query is returning the result, but my problem is when I tried to use the variable as shown below instead of TODAY I am not getting any result.
Date todayDate = date.today();
List<Task> taskList= [Select Id,status,LastModifiedDate from Task where LastModifiedDate=:todayDate];

you might say todayDate is the variable with date type and the last modified date is the DateTime field.  so it will not return any result, but why does it work in the first place with TODAY?
Shubham Jain 338Shubham Jain 338
Hi Karthik,
date.today(); is returning a fixed date with time as 00:00:00 that's why it is matching with a particular date and time record. Please debug in the anonymous block but in the case of TODAY, it is returning all the records of today's date.

Kindly mark as best answer if it helps


Thanks
Shubham Jain