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
santhosh konathala 8santhosh konathala 8 

How to fetch records on specific date using a query

Amit Chaudhary 8Amit Chaudhary 8
For single date you can try below query
SELECT id,name  FROM Account where CreatedDate  = 2012-11-06T06:46:56.000Z

User-added image

Please let us know if this will help you

Thanks
Amit Chaudhary
 
Vijay NagarathinamVijay Nagarathinam
Hi,

Use the below query it will work.

date d = system.today().addDays(-30);

Account [] acc= [select id from account where createdDate = :d];

Thanks,
Vijay
Amit Chaudhary 8Amit Chaudhary 8
There are to many out of the box varaible are available in SFDC no need of any code. please check below post
1) https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_dateformats.htm

For a spacific date please try below query
SELECT Id
FROM Account
WHERE CreatedDate > 2005-10-08T01:02:03Z

For YESTERDAY :- Starts 12:00:00 the day before and continues for 24 hours.
SELECT Id FROM Account WHERE CreatedDate = YESTERDAY
For this month :-THIS_MONTH :-
SELECT Id FROM Account WHERE CreatedDate < THIS_MONTH
Last n days :- LAST_N_DAYS:n
SELECT Id FROM Account WHERE CreatedDate = LAST_N_DAYS:365
Let us know if this will help you




 
Abhishek Prasad 66Abhishek Prasad 66
I dont know if someone is still looking for this, but Amit's solution will give u result on a partilar day, particular minute and second. I guess the ask was records created on a day.
Simple solution will be:
CreatedDate > 2019-03-17T00:00:01.00Z and CreatedDate < 2019-03-17T23:59:59.00Z

this will give the result for a particular day (whole day)
Suraj Tripathi 47Suraj Tripathi 47
Hi Santhosh,

You can try the below Query.
SELECT Id, Name FROM Account WHERE CreatedDate=Date.Today();
You can also give a date while filtering.
SELECT Id,Name FROM Account Where CreatedDate  = 2021-07-09T06:46:56.000Z

If you find your Solution then mark this as the best answer. 

Thank you!

Regards, 
Suraj Tripathi
Naman SinghNaman Singh
Try this
SELECT Id, Subject, CreatedDate FROM Case WHERE DAY_IN_WEEK(CreatedDate) = 6 AND DAY_ONLY(CreatedDate) = 2023-09-29

We use the DAY_IN_WEEK function to check if the day of the week when the Case was created is equal to 6, which corresponds to Friday (Sunday is 1, Monday is 2, and so on).
We use the DAY_ONLY function to compare the date part of the CreatedDate field to '2023-09-29',