+ Start a Discussion
banu201banu201 

How to get minimum date from list of dates in apex class.

Hi,

 

 

I need to find maximum date and minimum date from a list of dates.Can anyone give me solution??

 

Regards,

banu

Best Answer chosen by Admin (Salesforce Developers) 
Sam27Sam27

Well I am not sure how accurately 'sort' method would work, you would have to check it out by yourself. But if it does.

 

then suppose your list of date is 'datelist' then

 

datelist = datelist.sort();

 

date minDate = datelist.get(0);

date maxDate = datelist.get(datelist.size()-1);

 

would provide you with minimum and maximum date.

All Answers

ritika@developerforceritika@developerforce

Hi,

 

Simply do a 'sort' on the list of dates. Fetch the first element then, it will be the mimimum one.

 

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_list.htm , look for sort.

 

Hope this helps.

Sam27Sam27

Well I am not sure how accurately 'sort' method would work, you would have to check it out by yourself. But if it does.

 

then suppose your list of date is 'datelist' then

 

datelist = datelist.sort();

 

date minDate = datelist.get(0);

date maxDate = datelist.get(datelist.size()-1);

 

would provide you with minimum and maximum date.

This was selected as the best answer