Search code examples
sqlcoldfusioncoldfusion-9cfml

Listing Result by Date - showing at 8am - not midnight


I'm having a bit of a brain fart... Listing results of available slots by date. And it is set for showing a week ahead... But I'd like it to show the last result after 8am in the morning, rather than at midnight each night... Is there a way to do that?

This code below works fine for displaying the results, just shows it at midnight each night - and I'd like it to show the next result at 8am...

    <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 - I think I have it sorted using a cfif and cutting off last day - then searching for last day by itself when it is after 9am - works... But if anyone has any code cleanup suggestions - I'll take them...

This works below

   <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>

Solution

  • By cutting off the datelist above on my edited post above - I was able to accomplish this.

    Basically I pull the week - cut off the last date.

    Display the week exclusing the last day. And then after 9am - display the last day with a simple cfif statement on the 9am.