Help - Search - Members - Calendar
Full Version: Comparing Dates
W3Schools Forum > Server Scripting > ColdFusion
Andrew K.
Okay so I'm building this mini event system and I'm listing out all these like events into a page. So I was hoping to bold dates that are closer than a week away.

I have this little snippet of code and I was wondering what exactly to write instead of the bolded red text. I don't have much knowledge when it comes to manipulating dates.
QUOTE
<cfloop query="loopquery">
<cfif date of day 7 days away gte alertdate>
<li><b>#alertinfo# - Due #dateformat(alertdate, 'MMMM DD YYYY')#</b></li>
<cfelse>
<li>#alertinfo# - Due #dateformat(alertdate, 'MMMM DD YYYY')#</li>
</cfif>
</cfloop>
Skemcin
Try this:
CODE
<cfset cuedate = now() + 7)>
<cfloop query="loopquery">
<cfif cuedate gte alertdate>
<li><b>#alertinfo# - Due #dateformat(alertdate, 'MMMM DD YYYY')#</b></li>
<cfelse>
<li>#alertinfo# - Due #dateformat(alertdate, 'MMMM DD YYYY')#</li>
</cfif>
</cfloop>

I"m not at my CF server so I can't verify it for sure. But the idea is that before you loop set the constant (today's date plus 7 -- I called it cuedate) so that when you creep closer to your alert day it will become greater than that value. Then you will enter your condition.

Let me know how that works out.

To check what value is created with my <cfset> just <cfdump var="#cuedate#">. I'll check back since I think you might have to do a little more than just add seven to todays date.
Andrew K.
Thanks, with a little modification it worked perfectly. I never thought it would be so easy.

So how would I add a month, or a year to a date?
I'm guessing I can go plus 30 or whatever but I'm just wondering if there is a function or something for an easier way...
Skemcin
QUOTE (Andrew K. @ Jun 29 2007, 10:19 AM) *
Thanks, with a little modification it worked perfectly. I never thought it would be so easy.

So how would I add a month, or a year to a date?
I'm guessing I can go plus 30 or whatever but I'm just wondering if there is a function or something for an easier way...

Cool, glad you got it working. ColFusion can be pretty easy and its known to be have the fastest learning curve.

Anyway, off the top of my head I can't remember if there are some functions that might make it easier to do the month or year. But if you search the adobe coldfusion knowledge base for data and time functions, I'm sure you'll dig something up. Post your finding here for future reference.

Thanks.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.