+ Start a Discussion
The KnightThe Knight 

Is there a way to provide only date value to Datetime field

I am having one datetime field. I want to use it in where clause of soql. Can I mention only date value for that field and get all the values on that particular date?


Eg. DueDate- Datetime field.

      select ... from xyz where Duedate__c =only date no time to be mentioned


If there is any work around please let me know.


Any help would be appreciated.

Thanks in advance.


If the datatype of the field in question is datetime then the value you are providing should be in the datetime format, the closest you can do is leave the time portion with zeros.

Please find below an example:-

Normal DateTime with time component :- 2010-05-27T18:55:53.000Z

Normal DateTime with time component set to zeroes :- 2010-05-27T00:00:00.000Z   (time portion is in red)


Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.





If you want to do it that way, you can create a Date object on the fly to use in your SOQL


e.g. Date d = new Date(myDateTime.getYear(), myDateTime.getMonth(), myDateTime.getDay());


You'll have to check the syntax on that but once you've done it, just use your temp date object in your query.