+ Start a Discussion
sp13sp13 

query dateTime to date

how can i get the Date value of a DateTime field in query?
public Date myDate1 {get;set;}
public Date myDate2 {get;set;}

public List<Obj__c> getObj() {
          return[SELECT id, Name, Date_Time__c FROM Obj__c WHERE DATEVALUE(Date_Time__c) <=: myDate1 and DATEVALUE(Date_Time__c) >=: myDate2];
}

unfortunately, DATEVALUE(field) didn't work. is there anyway i can get the date value of Date_Time__c?
Best Answer chosen by sp13
Sure@DreamSure@Dream
Hi sp13,

I am not sure about DATEVALUE() function..but i think you can try by creating a formula field, containing the date value of the date_Time__c, and use that field in the query.

Thanks,
Suresh

All Answers

Vinita_SFDCVinita_SFDC
Hello,

What is the data type date_time__c? If it is dateTime then datvalue should work.
Sure@DreamSure@Dream
Hi sp13,

I am not sure about DATEVALUE() function..but i think you can try by creating a formula field, containing the date value of the date_Time__c, and use that field in the query.

Thanks,
Suresh
This was selected as the best answer