You need to sign in to do that
Don't have an account?
jojoforce
How to SOQL Query that has startdate and enddate
We have a custom object MyEvent__c with the following datetime fields StartDateTime__c and EndDateTime__c.
I am trying to get all of the current events and upcoming events.
For example, today is 9/14/2020 12:23 PM
Here is my query so far, but its not returning the correct results.
I am trying to get all of the current events and upcoming events.
For example, today is 9/14/2020 12:23 PM
Start Date/Time | End Date/Time | Results |
9/14/20 1:00 PM | 9/14/20 2:00 PM | Include |
9/14/20 9:00 AM | 9/14/20 1:00 PM | Include |
9/14/20 8:00 AM | 9/14/20 8:30 AM | Do Not Display |
9/14/20 1:00 PM | 9/16/20 7:00 PM | Include |
9/14/20 9:00 AM | 9/16/20 7:00 PM | Include |
9/16/20 9:00 AM | 9/16/20 7:00 PM | Do Not Display |
Here is my query so far, but its not returning the correct results.
SELECT Id, Name FROM MyEvent__c WHERE StartDate__c = TODAY OR (StartDate__c >=TODAY AND EndDate__c <= TODAY)
As you have stated >= this would mean that in case if the start date is greater or equal the expression would evaluate to true so I think there is no need for StartDate__c = TODAY.
Can you mention if it is working as in is it returning records or is it showing any error?
>> link for quick reference regarding the date comparison in soql query: https://www.wipfli.com/insights/articles/tc-date-comparisons-in-dynamic-soql-queries#:~:text=%3E%20resources%20%3D%20Database.-,query('Select%20Id%2C%20Name%20FROM%20Resource__c%20WHERE,today()%3B
Looking forward for your response.
Regards,
Anutej