+ Start a Discussion
MubarakMubarak 

How to get the number of records in a particular date range.

Hi all
How to get the number of records in  a particular date range.
For example i am having object called orderline.i want to get number of records were created during 12-jan-2014 to 12-dec-2014.
Currently am using force.com explorer so i need a query to get the expected result.

Thanks
Best Answer chosen by Mubarak
David ZhuDavid Zhu
or make sure there is no single quotation mark for dates and dates should be in YYYY-MM-DDThh:mm:ssZ format.

SELECT Name,createddate From orderline__c where createddate > 2015-03-04T01:02:03Z and createddate < 2015-03-31T01:02:03Z

SELECT count()  From orderline__c where createddate > 2015-03-04T01:02:03Z and createddate < 2015-03-31T01:02:03Z

All Answers

David ZhuDavid Zhu
date d1 = system.date.parse('01/31/2015');
date d2 = system.date.parse('03/31/2015');
list<orderline__c> a = [SELECT Name,createddate From orderline__c WHERE createddate > :d1 and createddate < :d2];
integer b = [SELECT count() From orderline__c WHERE createddate > :d1 and createddate < :d2];
system.debug(a);
system.debug(b);
David ZhuDavid Zhu
or make sure there is no single quotation mark for dates and dates should be in YYYY-MM-DDThh:mm:ssZ format.

SELECT Name,createddate From orderline__c where createddate > 2015-03-04T01:02:03Z and createddate < 2015-03-31T01:02:03Z

SELECT count()  From orderline__c where createddate > 2015-03-04T01:02:03Z and createddate < 2015-03-31T01:02:03Z
This was selected as the best answer