Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting Min and Max dates from available list of dates

Tags:

coldfusion

I have dates as a list in the following format:

09-2012,10-2012,01-2013 

What will be the better way to access the minimum and maximum dates from the list?

like image 352
user160820 Avatar asked Dec 16 '22 22:12

user160820


1 Answers

I'm not really sure which is faster. Here is my list-only-solution below , or you could convert the list to an array and work with that.

This does the job though:

<CFSET dates = "" />
<CFLOOP list="09-2012,10-2012,01-2013" index="date">
    <CFSET dates = listappend(dates,DateFormat(createDate(listlast(date,"-"),listfirst(date,"-"),1), "yyyy-mm-dd")) />
</CFLOOP>
<CFSET dates = listsort(dates,"numeric") />
<CFSET min_date = listfirst(dates) />
<CFSET max_date = listlast(dates) />
like image 176
Seybsen Avatar answered Jan 15 '23 23:01

Seybsen