Querying Dates
Hi all,
I am attempting to output some calendar dates from a database. I have a field called StartDate in the table formatted as mm/dd/yyyy. I'd like to output "future dates" for each month, so I've written this query:
<cfquery name="January" datasource="dsn">
SELECT *
FROM SITE:Calendar
WHERE DatePart('m', [StartDate]) = 1 and StartDate >= #Today# and Archive = 0
ORDER BY StartDate ASC, StartTime ASC
</cfquery>
FYI: #Today# is formatted as mm/dd/yyyy
This query works, but it also returns passed dates for the month. Question 1 is, why isn't the above query eliminating dates that have passed for the month of January? Is there a way to do this?
At another spot on the page, I'd like to output all dates less than #Today# that have passed for the current calendar year, so I've written this query:
<cfquery name="Past" datasource="dsn">
SELECT *
FROM SITE:Calendar
WHERE DatePart('yyyy', [StartDate]) = #Dateformat(Today, 'yyyy')# and StartDate < #Today# and Archive = 0
ORDER BY StartDate ASC, StartTime ASC
</cfquery>
This query returns 0 results, but there are quite a few records that should be counted. Question 2 is, can someone explain why this isn't working?
I appreciate in advance the help!
