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
debprakash shawdebprakash shaw 

how to write the Soql query for retrieve the record those are not in (from date to this date)

Hi,
I want to retrieve the record which is not on those dates like (Form_Date to To_Date )

Thanks in advance 
Best Answer chosen by debprakash shaw
Vijay Gaikwad 20Vijay Gaikwad 20
Hey debprakash shaw
try this 

SELECT name ,id ,Account.name ,CreatedDate from Contact WHERE  NOT  (CreatedDate >= 2022-04-20T23:01:01Z AND CreatedDate <= 2022-04-30T23:01:01Z)

All Answers

SwethaSwetha (Salesforce Developers) 
HI Deb,
Select id from Opportunity WHERE Start_Date__c <= 2015-07-30  AND End_Date__c >= 2015-05-01 

WHERE Start_Date__c <= 2015-07-30 //Latest date
End_Date__c >= 2015-05-01 //Earliest date

Related: https://salesforce.stackexchange.com/questions/80119/query-to-get-all-opportunities-that-between-start-and-end-date
https://developer.salesforce.com/forums/?id=906F00000008m41IAA

Thanks
debprakash shawdebprakash shaw
Hii Swetha
Thanks for giving an Answer but 
I want to retrieve the record which is not on those dates like (Form_Date to To_Date, the record does not show in-between days )
Vijay Gaikwad 20Vijay Gaikwad 20
SELECT name ,id ,Account.name ,CreatedDate from Contact WHERE  NOT  (CreatedDate >= 2022-04-20T23:01:01Z AND CreatedDate <= 2022-04-30T23:01:01Z)
Vijay Gaikwad 20Vijay Gaikwad 20
Hey debprakash shaw
try this 

SELECT name ,id ,Account.name ,CreatedDate from Contact WHERE  NOT  (CreatedDate >= 2022-04-20T23:01:01Z AND CreatedDate <= 2022-04-30T23:01:01Z)
This was selected as the best answer
debprakash shawdebprakash shaw
SELECT name ,id ,Account.name ,CreatedDate from Contact WHERE  NOT  (CreatedDate >= 2022-04-20T23:01:01Z AND CreatedDate <= 2022-04-30T23:01:01Z)
In this query, I want to filter any specific contact record then how can write?

like:-
SELECT name ,id ,Account.name ,CreatedDate from Contact WHERE  NOT  (CreatedDate >= 2022-04-20T23:01:01Z AND CreatedDate <= 2022-04-30T23:01:01Z) And account.id=' ' 

thanks in advance
debprakash shawdebprakash shaw
SELECT name ,id ,Account.name ,CreatedDate from Contact WHERE  NOT  (CreatedDate >= 2022-04-20T23:01:01Z AND CreatedDate <= 2022-04-30T23:01:01Z)
In this query, I want to filter any specific contact record then how can write?
 like :- And Id ='0021578de62de52'
how to add this in this query

'0021578de62de52' :-- this is only a example ,this is not real id

Thank In Advance 
 
debprakash shawdebprakash shaw
SELECT name ,id ,Account.name ,CreatedDate from Contact WHERE  (NOT  (CreatedDate >= 2022-04-20T23:01:01Z AND CreatedDate <= 2022-04-30T23:01:01Z)) And (Id ='0035g00000b7gSHAAY')