按日期列出结果 - 显示在上午8点 - 而不是午夜

时间:2013-12-05 17:04:24

标签: sql coldfusion coldfusion-9 cfml

我有一点脑屁...按日期列出可用插槽的结果。并且它将在未来一周展示......但我希望它能在早上8点之后显示最后的结果,而不是每晚的午夜......有没有办法做到这一点?

下面这段代码可以很好地显示结果,只在每晚的午夜显示 - 我希望它能在上午8点显示下一个结果......

    <cfset datelist = #DateAdd("d", tydef.numdays, todaydate)#>

   <cfquery name="list" datasource="#ds#">
    select * from shindates
    where sdate >= #createODBCDate(todaydate)# 
    and stime >= #createODBCDateTime(timehr)# 
    and sdate <= #createODBCDateTime(datelist)# 
    and typeid = '#ty.typeid#'
    order by sdate, stime
   </cfquery>

K - 我想我已经使用cfif排序并切断了最后一天 - 然后在上午9点之后搜索最后一天 - 工作......但是如果有人有任何代码清理建议 - 我会采取他们...

这可以在

下面工作
   <cfset datelist = #DateAdd("d", tydef.numdays, todaydate)#>

   <cfset sdatelist = #DateAdd("d", -1, datelist)#>

   <cfset stime = CreateTime(9,0,0)>

   <cfquery name="shinny" datasource="#ds#">
    select * from shindates
    where sdate >= <cfqueryparam cfsqltype="cf_sql_date" value="#todaydate#">
    and stime >= <cfqueryparam cfsqltype="cf_sql_time" value="#timehr#">
    and sdate <= <cfqueryparam cfsqltype="cf_sql_date" value="#sdatelist#"> 
    and typeid = '#ty.typeid#'
    order by sdate, stime
   </cfquery>

   <cfif #DatePart("h", timenow)# GTE #DatePart("h", stime)#>

   <cfquery name="lastday" datasource="#ds#">
    select * from shindates
    where sdate >= <cfqueryparam cfsqltype="cf_sql_date" value="#datelist#">
    and sdate <= <cfqueryparam cfsqltype="cf_sql_date" value="#datelist#"> 
    and typeid = '#ty.typeid#'
    order by sdate, stime
    </cfquery>

    </cfif>

2 个答案:

答案 0 :(得分:0)

最可能的罪魁祸首是:

and stime >= #createODBCDateTime(timehr)#

CreateODBCDateTime()创建一个datetime对象。如果您只是提供一次,它将使用当前日期。

解决方案是使用正确的数据类型。我假设你已经做过这样的事情:

<cfset stime = CreateTime(8,0,0)>

在这种情况下,您需要在查询中使用此功能。

 and stime >= <cfqueryparam cfsqltype="cf_sql_time" value="#stime#">

由于各种原因,您希望对查询中的每个变量使用查询参数。这将消除使用CreateODBCDateTime()的需要。

答案 1 :(得分:0)

通过在上面编辑的帖子上删除上面的日期列表 - 我能够完成此任务。

基本上我拉了一周 - 切断了最后一个日期。

显示排除最后一天的一周。然后在上午9点之后 - 在上午9点用简单的cfif语句显示最后一天。