Jump to content

Comparing Dates


Recommended Posts

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.

<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>
Link to post
Share on other sites

Try this:

<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.

Link to post
Share on other sites

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...

Link to post
Share on other sites
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.
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...