I'd suggest using DateCompare("date1", "date2" [, "datePart"]) to perform the evaluation, since it works specifically on Date/time values. I typically use datePart = "d" to compare to the day. The "GTE" operators in your code are probably performing string, not date/time, comparisions and may never yield desired results.
• -1, if date1 is earlier than date2
• 0, if date1 is equal to date2
• 1, if date1 is later than date2
Nothing probable about it, the original code is comparing a string that represents a date to humans to a number the represents a date to a computer.
To confirm the dateCompare() function is what is desirable here but I want to take a moment to expand on what the original code was doing.
if #dateformat(GetFlyers.endDate,"m/d/yy")# GTE #NOW()# This comes down to the following process inside the computer.
IF the string '7/4/09' IS GREAT THEN OR EQUAL TO the timeStamp 14567896756 [NOTE: all values are completely imaginary]
One has to understand that dates are not simple things that many assume they are and work with them appropriately.
Message was edited by: Ian Skinner
I hadn't run across DateCompare(), but now that Sherlock pointed me to it, I see I'll use it more and more. Thanks also to Ian for his imput. I did note you really have to think about the -1, 0, and 1 values however. Had to scratch my head a bit on that part. ;-) I am now producing a list of promotion dates (from/thru) which I'll turn into a link to the actual PDF. This is just what the doctor ordered. I also will use this same technique on another page to link from a manufacturer logo and perform an item search to show the actual promo items from that manufacturer. This is great guys. Thanks!
My final working code now looks like this:
<cfquery name="GetFlyers" datasource="sales">
select * from flyers
order by startdate
<cfset ValidBeforeToday = DateCompare(#startDate#, #Now()#,"d")>
<cfset ValidAfterToday = DateCompare(#EndDate#, #Now()#,"d")>
<cfif ValidBeforeToday GTE -1 and ValidAfterToday GTE 0>
#dateformat(GetFlyers.startDate,"m/d/yy")# thru #dateformat(GetFlyers.endDate,"m/dd/yy")# <br />
I did note you really have to think about the -1, 0, and 1 values however. Had to scratch my head a bit on that part. ;-)
Yes, even after years of CF development dealing with all types of date issues, I still have to paper proof the logic of a dateCompare if statement.