I'm working on a client's site, and he needs coupon expiration dates to change red if they're two weeks or less to expiring. Otherwise they will be black.
The site itself was not made by me. I just started here and they want me to learn ColdFusion. So I've been stumbling through it.
I thought that maybe by using DateCompare or DateDiff I could get what I want. However I get garbled text when I <CFOUTPUT>
the results of either comparison. It displays a long string of 51515151551
that gradually gets smaller and smaller for each subsequent coupon item on the customers list.
The coupon date itself (ie end_date) is called from the Microsoft SQL database. It is formatted using Dateformat: #dateformat(end_date,"m/d/yyyy")#
.
I tried to compare it with Now()
in order to dynamically determine whether or not the expiration date should be colored red. I've also tried formatting Now()
, I get the same results.
Any seasoned programmers here that could lead me to the right path?
Datediff is what you want. Are you using the correct date part in date diff? You could use 'ww' for weeks or 'd' for days, I used days in the below example.
<cfset CouponDate = createDate( 2012, 05, 29 ) />
<cfif DateDiff( "d", CouponDate, Now() ) GTE 14>
<cfset Expired = False />
<cfelse>
<cfset Expired = True />
</cfif>
Obviously you don't need to set a variable or anything, this is just some example code to get your idea working. :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With