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

Access createddate in query




My requirement is to generate a visual force report based on lead created date. I need to take the created date as input and use it in the query to get only those records which were created on that date.


I am able to get it into the controller but unable to use it in the query. Please help......








When you are using the input from the Vf page format of the input will be text. Before using that you have to parse the date into the date/date time format


Use the below code sample as reference


String datevalue=’01/1/2012’;
string[] mydate=datevalue.split('/');
integer year=integer.valueOf(mydate[2]);
integer month=integer.valueOf(mydate[1]);
integer day=integer.valueOf(mydate[0]);
Datetime GMTDate = Datetime.newInstanceGmt(year,day,month,0,0,0);
string strConvertedDate= GMTDate.format('yyyy-MM-dd\'T\'hh:mm:ss\'Z\'');

list< lead >uu=[select id,name from lead where createddate <: strConvertedDate];




String datevalue=’01/1/2012’;
datetime dd=date.parse(value)
string strConvertedDate=dd.format('yyyy-MM-dd\'T\'hh:mm:ss\'Z\'');
list< lead >uu=[select id,name from lead where createddate <: strConvertedDate];


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