Skip to main content
Known Participant
February 3, 2011
Question

Select dates for this month

  • February 3, 2011
  • 2 replies
  • 451 views

Hi all,

I'm creating a calendar output for a site and I've run into a problem with my query.  When the page loads, CF sets now() to "Today."  What I'm trying to do is pull all the dates from a db table for the current month based on now().  I keep getting the "too few parameters expected" error.  Would someone mind looking at my code to see if they can find an issue?

<cfset Today = "#Dateformat(now(), "MM/DD/YYYY")#">

<cfquery name="GetEvents" datasource="DataS">

     SELECT StartDate,EndDate,Event,Description,Place,StartTime,EndTime,AllDay,AllMonth,HmPg,Ongoing

     FROM CalendarData

    WHERE #DatePart("m", Today)# = #DatePart("m", StartDate)#

     AND StartDate >= #Today#

     AND HmPg = 1

    ORDER BY StartDate ASC, StartTime ASC

</cfquery>

I have a similar query in another area of the site, but the WHERE clause reads WHERE #DatePart("m", StartDate)# = #CalMonth# where CalMonth is set to a number depending on which month a user clicks on.  I want the query above to update dates for each month automatically.

Thank you!

    This topic has been closed for replies.

    2 replies

    Participating Frequently
    February 3, 2011

    You're trying to mix ColdFusion functions with database fields in a

    way that it can't be done (basically your code tries to run the

    DatePart ColdFusion function for every row, while the database is

    trying to decide what rows to retrieve).

    Instead of the CF function DatePart use the appropriate database

    function for what you're trying to do (I think for access

    "Month(startDate)" should work).

    --

    Mack

    Inspiring
    February 3, 2011

    There are lots of issues with your code but instead of listing them all, I'll suggest a different approach.  Use ColdFusion date functions to find the start of the current month and the start of the following month.  Let's call those variables DateA and DateB.

    The where clause of your query then becomes

    where yourdatefield >= DateA

    and yourdatefield < DateB