Question

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>
Was it helpful?

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.

OTHER TIPS

The most likely culprit is:

and stime >= #createODBCDateTime(timehr)#

CreateODBCDateTime() creates a datetime object. If you simply supply it a time, it will use the current date.

The solution is to use proper datatypes. I assume you already did something like this:

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

That being the case, you want this in your query.

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

For a variety of reasons, you want to use query parameters for every variable in your query. This will eliminate the need to use CreateODBCDateTime().

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top