Coldfusion takes a list of dates and sets them in the correct date order

Grabbing dated dates from the database and adding new ones to the list, and then you need to put all the dates in the correct date order.

<cfparam default="" name="newDates">
<cfloop index="tm" from="#form.arrive#" to="#form.depart#" step="#createTimespan(1,0,0,0)#">    

<cfset newDates = newDates & '#dateFormat( tm, "mm/dd/yyyy" )#,'>

</cfloop>
<cfset penddate = '#pmonthlist#, #newDates#'>

      

How can I take the results of this.

7/15 / 2012.7 / 16 / 2012.7 / 17 / 2012.7 / 18 / 2012.7 / 19 / 2012.7 / 20 / 2012.7 / 21 / 2012.9 / 21/2012, 9 / 22 / 2012.9 / 28 / 2012.9 / 29 / 2012.04 / 01 / 2012.04 / 02 / 2012.04 / 03 / 2012.04 / 04 / 2012.04 / 05 / 2012.04 / 06 / 2012.04 / 07/2012,

And do it in the correct date order like this. (these are the results I want)

04/01 / 2012.04 / 02 / 2012.04 / 03 / 2012.04 / 04 / 2012.04 / 05 / 2012.04 / 06 / 2012.04 / 07 / 2012.7 / 15/2012, 7 / 16 / 2012.7 / 17 / 2012.7 / 18 / 2012.7 / 19 / 2012.7 / 20 / 2012.7 / 21 / 2012.9 / 21 / 2012.9 / 22 / 2012.9 / 28 / 2012.9 / 29/2012

+3


source to share


1 answer


UPDATE: Solution # 0 - just sort them with arraySort(dates, 'numeric')

(doesn't work in Railo), see http://www.cfgears.com/index.cfm/2010/10/7/Using-an-array-to-sort- dates

Solution # 1 - sorting the date array

  • Turn the list dates

    into an array usingListToArray()

  • through the array and DateFormat()

    them likeYYYYMMDD

  • arraySort(dates, 'numeric')

  • write down the dates again and put DateFormat()

    them back inM/D/YYYY

  • ArrayToList()

Solution # 2 - Using Query Query

  • If you have a query object with date entries, skip to step 2.
  • set myQuery as QueryNew ('MyDate', 'Date')
  • write down the dates and add them to the request with QueryAddRow()

    andQuerySetCell()

  • use query requests: SELECT MyDate FROM myQuery ORDER BY MyDate

  • ValueList(myQuery.myDate)

Solution # 3 - use Java



  • include a list of dates in an array
  • through an array, use javacast

    to cast each date asjava.util.Date

  • invoke sort()

    in java.util.Collections

    an array

Solution # 4 - use DateCompare()

  • include a list of dates in an array
  • write your own sorting algorithm (? bubble sort?) using DateCompare()

    date comparison.

Solution # 5 - use a DB temporary table

  • insert into temp table
  • select ORDER BY

+8


source







All Articles