0

我有 2 个冷融合日期,比如

from: 2013-03-29 00:00:00.0 
to: 2013-04-05 00:00:00.0 

我想创建这两个日期之间所有日期的列表,例如

29.03.2013,30.03.2013,31.03.2013,......,05.04.2013

是否有可用的功能,或者我必须从 to 循环date_fromdate_to创建一个列表?

4

1 回答 1

3

有趣的是,您可以使用 cfloop 循环日期,而“索引”是自 Epoch 以来的天数,您也可以将其视为日期。通过对其执行日期函数,例如使用 dateAdd,它将其转换为日期对象。

<cfset date_From = createDate(2013, 3, 29)>
<cfset date_To = createDate(2013, 4, 5)>

<cfset allDates = []>

<cfloop from="#date_from#" to="#date_to#" index="i">
    <cfoutput>
    #i#<br>
    </cfoutput>

    <!--- adding zero will do nothing to the date other than turn it into a date object --->
    <cfset newDate = dateadd("d", 0, i)>

    <cfset arrayAppend(allDates, newDate)>
</cfloop>

<cfdump var="#allDates#">
于 2012-11-19T09:52:13.597 回答