Below is the aggregate result query to get the minimum and maximum date values(start and end) from an object , objX. However the ask is to extract only the year from the result. How can that be done? I tried using certain methods such as date.year(), but without success.
AggregateResult[] groupedResults = [Select min(Start_Date__c),max(End_Date__c) from ObjX__c where id in :setbpid ];
system.debug('**aggres'+groupedResults );
Integer minyear = minbp.EPCP_Start_Date__c.year();
for (AggregateResult ar : groupedResults) {
system.debug('****&&&&^^^');
System.debug('Min Date' + ar.get('expr0'));
System.debug('Max Date + ar.get('expr1'));
Date d = ar.get('expr0');
Integer maxyear = d.year();
system.debug('****intmax'+maxyear);
}