我遇到了一些麻烦CreateDate()
函数,它只是出错,我不知道为什么!
我正在运行此查询以获取新闻报道中的所有日期,以便我可以每月创建一个新闻档案。
<cfquery name="selectNews" datasource="#Request.dsn#">
SELECT Month(NewsDate) AS theCount
FROM news
GROUP BY Month(NewsDate)
</cfquery>
然后当我输出它时,我尝试以以下格式输出它
- Aug 2012
- 2012年9月
- Oct 2012
所以我使用下面的代码来尝试输出这个列表
<ul>
<cfloop query="selectNews">
<cfoutput>
<cfset theDay = DateFormat(Now(), 'dd')>
<cfset theMon = theCount>
<cfset theYear = DateFormat(Now(), 'yyyy')>
<li>#CreateDate(theYear, theMon, theDay)#</li>
</cfoutput>
</cfloop>
</ul>
它对于第一项效果很好,它将输出Aug 2012
,但是它会出错,说这个
Error Occurred While Processing Request
MONTH
至少对我来说,这毫无用处!
我的猜测是SQL 月份() http://msdn.microsoft.com/en-us/library/ms187813.aspx函数返回 0 表示一月并且创建日期 http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=functions_c-d_09.html预计 1 月份为 1。
Edit
<ul>
<cfloop query="selectNews">
<cfset theDay = Day(Now())>
<cfset theMon = #theCount#>
<cfset theYear = Year(Now())>
<cfoutput><li>#DateFormat(CreateDate(theYear, theMon, theDay), "mmm yyyy")#</li></cfoutput>
</cfloop>
</ul>
Edit
这似乎有效,但仅适用于奇数月份
<cfset months = [1,3,5] />
<ul>
<cfloop array="#months#" index="currentmonth">
<cfoutput><li>#DateFormat(CreateDate(Year(Now()), currentmonth, Day(Now())), "mmm yyyy")#</li></cfoutput>
</cfloop>
</ul>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)