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
Gheorghe Sima 25Gheorghe Sima 25 

How to use a date field in a query?

Hi,
I want to make a query with some parameters, but i don't know how to use a date field in it.
This is my code:
myQuery = 'select Name, Start_Date__c, Contact__c, Country__c, Data_Check_In__c, Data_Check_Out__c,Id from Visit__c'; 

if(myVisit.Start_Date__c != null || myVisit.Country__c != null)
     myQuery += ' where ';

     if (myVisit.Start_Date__c != null)
     {
         myQuery += ' Start_Date__c = ' + String.ValueOf(myVisit.Start_Date__c.day()) + '/' + String.ValueOf(myVisit.Start_Date__c.month()) + '/' + String.ValueOf(myVisit.Start_Date__c.year());
         if(myVisit.Country__c != null) myQuery+=' and ';
     }
if(myVisit.Country__c != null)
{
       myQuery += ' Country__c = \'' + myVisit.Country__c + '\'';
}
myQuery += ' LIMIT 20';

I recive the error : unexpected token: '/'. I also use the following sintax: myQuery += ' Start_Date__c = ' + myVisit.Start_Date__c, but it doesn't work.
Can anyone help me?