2

我很尴尬地承认,在日期和日期逻辑 ColdFusion 方面我并不是最出色的。

<!---checks frequency for form schedule and sets datepart. RecordType_Frequency is a column in database daily, weekly, monthly etc.--->

<CFSWITCH expression="#RecordType_Frequency#">
     <CFCASE value="Daily">
       <CFSET datepart = "d">
     </CFCASE>
     <CFCASE value="Weekly">
       <CFSET datepart = "ww">
     </CFCASE>
     <CFCASE value="Monthly">
       <CFSET datepart = "m">
     </CFCASE>
     <CFCASE value="Quarterly">
       <CFSET datepart = "q">
     </CFCASE>
     <CFCASE value="Yearly">
       <CFSET datepart = "yyyy">
     </CFCASE>
</CFSWITCH>

 <!---setting dates based on database values for when the form should schedule--->

 <!---enddate Uses the RecordType_Frequency_StartDate column from the database which is a date in the past. Coefficient is a stored db value for the frequency 1,2 etc. for could scheduled every 1 year, 2 year --->

 <cfset enddate = datediff(datepart,RecordType_Frequency_StartDate,todaydate) + Coefficient>

 <!---start date is set to current RecordType_Frequency_StartDate which is a column   value from the database--->

 <cfset startdate = RecordType_Frequency_StartDate>

 <!---sets the next start date for when the for should schedule based on historic db start date--->

 <cfset new_date = dateformat(DateADD(datepart,Coefficient,startdate),'MM-DD-YYYY')>

 <cfloop from="1" to="#enddate#" index="i">

   <cfset new_date = dateformat(DateADD(datepart,Coefficient,startdate),'MM-DD-YYYY')>

   <cfset startdate = new_date>

   <cfset diff = datediff(datepart,RecordType_Frequency_StartDate,startdate)>

   <cfif (startdate GT todaydate)>

      <cfset next_date= startdate>

  <cfoutput>

    <!---I need this output to equal the next date value that would fall based on the schedule, future date. I am seeing multiple dates and need to figure out how to capture would weould truly be the next scheduled date---> 

     Next Date = #diff# - #dateformat(next_date)#<br />

  </cfoutput>

 </cfif>

  </cfloop>

总之,我有一些按计划进行的表格。开始/设置日期是我必须使用的唯一日期。我需要使用我拥有的信息来获取或填充表单的下一个预定日期。显然,下一个创建日期需要在未来,因为该日期将与预定事件一起使用。

我已经发布了带有注释的代码,需要帮助来获取最接近当前日期的下一个逻辑日期,该日期应该按顺序排列。

4

2 回答 2

2

http://cfquickdocs.com/#DateAdd

如果您只需要下一个可能的日期,请使用 dateadd() 函数。

例如,如果您想在下一个工作日使用:dateadd("w", 1, now())

于 2012-06-14T02:58:44.957 回答
0

假设我了解您的问题,那么我不久前写的 UDF 可能会解决您的问题:

http://www.bryantwebconsulting.com/blog/index.cfm/2011/2/24/EnglinshFriendly-Interval-Calculation

在“interval”参数的其他几个选项中,它还应该接受您在 switch 块中使用的选项。

于 2012-06-14T14:10:42.817 回答