• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

What is the best way to check date range?

Explorer ,
Nov 09, 2011 Nov 09, 2011

Copy link to clipboard

Copied

I have a table with some important dates in it. Say 11/9/2011, 11/10/2011 and 11/12/2011.

I have a form where users can select a start date for an event and an end date.

I will be displaying the results of the form in a table and I wanted to color code the row a different color if the a date within the date range between the start date and end date is one of the dates in the table.

I'm all set with coloring the row but I'm having trouble doing the date checks on the fly. Any ideas how I can do this?

So for instance Start date = 11/5/2011, end date = 12/01/2011. I need to first get the range of dates and second check each day to see if it is 11/9/2011, 11/10/2011 or 11/12/2011. If any of the dates within that range equal the table dates I will color code that entry different.

TOPICS
Advanced techniques

Views

802

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 09, 2011 Nov 09, 2011

Copy link to clipboard

Copied

If you are on CF9, the ternary operator will work quite nicely.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 09, 2011 Nov 09, 2011

Copy link to clipboard

Copied

I'm actually in CF9 on our development server but CF8 in prod and test still where I need to set this up. That does sound interesting and I'll have to keep that in mind for future development. Is there a way in CF8 to do this?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 09, 2011 Nov 09, 2011

Copy link to clipboard

Copied

Either

<tr bgcolor=<cfif something>colour1<cfelse>colour2</cfif>

or

<tr valign="top" bgcolor="#iif(condition goes here, de('colour1'), de(colour2))#">

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Nov 11, 2011 Nov 11, 2011

Copy link to clipboard

Copied

LATEST

Are you creating a new row in your table for each date between your range and you just want to highlight the rows that match your "special" dates?  I think a ListFind() would work well here, unless you have a bazillion "special" dates:

<!--- build special list (probably this will come from a DB Query + ValueList() call--->

<cfset sMyDatesList = "11/5/2011,11/10/2011,11/12/2011">

<!--- inside your loop --->

<tr <cfif ListFind(sMyDatesList, DateFormat(dtIncrementingDateVar, "m/d/yyyy")>class="special_date_class"</cfif>>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation