0 votes
1 view
in Salesforce by (11.9k points)

Is there a way (without creating a formula datevalue(datetime) field) to aggregate a SOQL query on the date portion of a DateTime field? For example, I'd like to do something like:

select datevalue(datetimeField), count(Id) from object__c group by datevalue(datetimeField)

1 Answer

0 votes
by (31.8k points)

You can't really group on a DateTime field instantly, there are plenty of date/time functions for aggregates. By which you can group by section of the DateTime value. For example, here's a query that'll show the number of account records created on each date.

select day_only(createdDate) createdonDate, 

    count(createdDate) numCreated 

    from account 

    group by day_only(createdDate) 

    order by day_only(createdDate) desc

Note: day_only() is used to return the date part of a DateTime field.

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...