You need to sign in to do that
Don't have an account?
sales4ce
SOQL Query to compare Dates
Hi,
I have a Custom Object Called "Visit" which has two custom date fields , StartDate__c and EndDate__c.
I have a Soql Query which needs to compare whether visit record is withinthe date range.
My SOQL query returns an error saying "List has No rows of data".
example: i have a visit record which has a start date as 2011-05-10 and End Date as 2011-05-17.
Can anyone point me what i am doing wrong?
Apex class:
public class visit {
visit__c todaysvisit;
String displayvisit;
Date today=Date.Today();
Public visit(){
System.Debug('Todays date is >>>'+today);
todaysvisit=[Select Visit__c From Visit__c Where Visit_Start_Date__ >= today AND Visit_End_Date__c <= today Limit 1 ];
displayvisit=todaysvisit.visit__c;
}
Public Tip__c gettodaysvisit(){
return todaysvisit;
}
Public String getdisplayvisit(){
return displayvisit;
}
}
Thanks,
Sales4ce
Thanks for your reply.
But was there anything wrong with my query as i get an exception at the query level?I am just making sure to get only the record that falls with in the Start and End Dates?
Any thoughts on the query?
Sales4ce
I am not sure that you are able to select a record using the Object API, instead you would need to find a record based off the ID. I am making the assumption that you don't have a record field named visit__c inside of your object named visit__c.
Hi,
not sure if you've spotted this but try this query:
todaysvisit=[Select Visit__c From Visit__c Where Visit_Start_Date__ >= :today AND Visit_End_Date__c <= :today Limit 1 ];
I only added colon before the today in the query.
Hope it helps!
Cheers!
Martin
Martin,
i am still unable to get it to work.
how do i write a query that checks whether the current date falls within the start and end date of my record.
Any ideas?
Thanks,
Sales4ce
Hi sales4ce,
I did a quick example which work for me (not your object, but I do comparisons on dates).
Martin,
Thanks for the help.
I was able to figure out where i was going wrong. I wasn't comapring the dates correctly.
Sales4ce