Skip to main content
Inspiring
June 5, 2007
Answered

Retrieving records by date

  • June 5, 2007
  • 3 replies
  • 337 views
I've been having a tough time with retrieving records before a certain date.

I had this code working on a site in the past and for some reason, it's not working anymore - don't know if it's because of a ColdFusion upgrade or if I missed something.

I am trying to bring up only records that have a date code from earlier than now (so we can set up some records to appear on the site later...)

I am using:

SELECT PostID, Title, Post, ImageBox, DatePosted, Active
FROM TheRecords
WHERE (DatePosted < #Now()#) AND (Active = 'Yes')
ORDER BY DatePosted DESC

Though it doesn't give an error, it seems to retrieve all of the records, even those that are scheduled for later.

Any ideas?

Thanks!

Luc
    This topic has been closed for replies.
    Correct answer cf_dev2
    If "DatePosted" is not a date type column, that may be the source of your problem. Otherwise, cfdump the query and check the results. Are the "DatePosted" values less than "CurrentTime" ? If they are, it suggests a problem with the values in the "DatePosted" column, rather than your where clause.


    SELECT PostID, Title, Post, ImageBox, DatePosted, Active, #Now()# AS CurrentTime
    FROM TheRecords
    WHERE DatePosted < #Now()# AND Active = 'Yes'
    ORDER BY DatePosted DESC

    3 replies

    ltherAuthor
    Inspiring
    June 5, 2007
    Thanks a lot for the reply. That seems to be exactly what it was - it was set as varchar.

    jdeline, thanks a lot for your help too!

    Luc
    cf_dev2Correct answer
    Inspiring
    June 5, 2007
    If "DatePosted" is not a date type column, that may be the source of your problem. Otherwise, cfdump the query and check the results. Are the "DatePosted" values less than "CurrentTime" ? If they are, it suggests a problem with the values in the "DatePosted" column, rather than your where clause.


    SELECT PostID, Title, Post, ImageBox, DatePosted, Active, #Now()# AS CurrentTime
    FROM TheRecords
    WHERE DatePosted < #Now()# AND Active = 'Yes'
    ORDER BY DatePosted DESC
    June 5, 2007
    What database are you using and what is the data type of DatePosted?