openbd cfloop 超过一个日期

发布于 2024-07-09 02:10:53 字数 372 浏览 9 评论 0原文

我正在尝试将我的网站从 CF8 转换为 openBD。 我的网站中有一个 cfloop,可以在某个日期范围内循环。

本质上,我想在日期范围(从和到)的每 2 周(步骤)向数据库中插入一条新记录,

我的循环如下所示...

<cfloop 
  from  = "#form.startDate#" 
  to    = "#form.endDate#" 
  index = "i" 
  step  = "#theStep#"
>

这在 CF8 中完美运行,在 openBD 中,我收到此错误... 不支持数据:值 [11/05/09] 不是数字

有解决办法吗?

谢谢

I'm trying to convert my sites from CF8 to openBD. I have a cfloop in a site that loops over a date range.

In essence, I want to insert a new record into the db for every 2 weeks (step) of a date range (from and to)

my loop looks like this...

<cfloop 
  from  = "#form.startDate#" 
  to    = "#form.endDate#" 
  index = "i" 
  step  = "#theStep#"
>

This works perfectly in CF8, in openBD, I get this error...
Data not supported: value [11/05/09] is not a number

Any ideas of a work around?

Thx

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

梦过后 2024-07-16 02:10:53

您的问题在于没有检查表单中不明确的区域设置相关日期字符串。

一个更强大的版本是这样的:

<cfset SetLocale("English (US)")> <!--- set expected input locale here --->

<cfif LSIsDate(form.startDate) and LSIsDate(form.endDate)>
  <cfset theStep = 14>

  <cfloop 
    from  = "#LSParseDate(form.startDate)#" 
    to    = "#LSParseDate(form.endDate)#" 
    index = "i" 
    step  = "#theStep#"
  >
    <!--- do stuff --->
  </cfloop>
<cfelse>
  <!--- output some error message --->
</cfif>

限制人们在表格中输入明确的日期格式(例如“yyyy-mm-dd”)将很有帮助。

“值不是数字”错误来自这样一个事实:即使您向循环提供日期,循环仍然会遍历数字。 然后,它使用这些日期的数字表示,但它们必须有效且易于理解才能正常工作。

Your problem lies in not checking for ambiguous locale dependent date strings from your FORM.

A more robust version would be this:

<cfset SetLocale("English (US)")> <!--- set expected input locale here --->

<cfif LSIsDate(form.startDate) and LSIsDate(form.endDate)>
  <cfset theStep = 14>

  <cfloop 
    from  = "#LSParseDate(form.startDate)#" 
    to    = "#LSParseDate(form.endDate)#" 
    index = "i" 
    step  = "#theStep#"
  >
    <!--- do stuff --->
  </cfloop>
<cfelse>
  <!--- output some error message --->
</cfif>

It would be helpful to restrict people to entering unambiguous date formats into the FORM, like "yyyy-mm-dd".

The "value is not a number" error comes from the fact that the loop still goes over numbers, even if you feed it dates. It uses a numerical representation of these dates then, but they must be valid and intelligible for that to work.

清浅ˋ旧时光 2024-07-16 02:10:53

我看不到你的代码,但这是我的第一个建议:

<cfset current = [your begin date]>
<cfloop condition = "datecompare(enddate, current)">
  [do stuff]
  <cfset current = dateadd('d', 14, current)>
</cfloop>

HTH。

I can't see your code, but here's my first suggestion:

<cfset current = [your begin date]>
<cfloop condition = "datecompare(enddate, current)">
  [do stuff]
  <cfset current = dateadd('d', 14, current)>
</cfloop>

HTH.

月寒剑心 2024-07-16 02:10:53

正如 Ben 所说,您的代码不存在 - 您需要使用 101 010 图标为其创建代码块。

这是另一个应该有效的解决方案:

<cfloop index="Current" from="#parseDateTime(StartDate)#" to="#parseDateTime(EndDate)#" step="14">
    [do stuff]
</cfloop>

As Ben says, your code isn't there - you need to use the 101 010 icon to create a code block for it.

Here's another solution which should work:

<cfloop index="Current" from="#parseDateTime(StartDate)#" to="#parseDateTime(EndDate)#" step="14">
    [do stuff]
</cfloop>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文