how-format-cells-or-rows-based-on-multiple-date-ranges

Questionshow-format-cells-or-rows-based-on-multiple-date-ranges
Jeff asked 4 hours ago

I\’m successfully using the code below to color cells that contain a date that is at least three years in the past: … $threeYearsAgo = date(\’Y-m-d\’, strtotime(\’-3 years\’)); // If date is three years or more in the past, change CSS of cell $f = array(); $f[\”column\”] = \”date_capitalized\”; $f[\”op\”] = \”<=\”; $f[\”value\”] = $threeYearsAgo; //$f[\”cellclass\”] = \”focus-date\”; $f[\”cellcss\”] = \”\’background\’:\’rgba(255, 255, 0, 0.3)\’\”; //$f[\”css\”] = \”\’background-color\’:\’#ff0000\’, \’color\’:\’white\’\”; // Applies to the entire row, not just the cell $f_conditions[] = $f; … Two questions: The code above also changes the color of the cells if no date is present (i.e., NULL value). How can I edit the code to stop coloring cells that do not contain a date? How can I color the cells different colors based on date range? Yellow if the date is at least 3 years in the past. Orange if the date is at least 4 years in the past. Red if the date is at least 5 years or more in the paste.

1 Answers
Jeff answered 4 hours ago

I’m successfully using the code below to color cells that contain a date that is at least three years in the past:


$threeYearsAgo = date('Y-m-d', strtotime('-3 years'));
// If date is three years or more in the past, change CSS of cell
$f = array();
$f["column"] = "date_capitalized";
$f["op"] = "<=";
$f["value"] = $threeYearsAgo;
//$f["cellclass"] = "focus-date";
$f["cellcss"] = "'background':'rgba(255, 255, 0, 0.3)'";
//$f["css"] = "'background-color':'#ff0000', 'color':'white'"; // Applies to the entire row, not just the cell
$f_conditions[] = $f;

Two questions:

  1. The code above also changes the color of the cells if no date is present (i.e., NULL value). How can I edit the code to stop coloring cells that do not contain a date?
  2. How can I color the cells different colors based on date range?
    • Yellow if the date is at least 3 years in the past.
    • Orange if the date is at least 4 years in the past.
    • Red if the date is at least 5 years or more in the paste.
Your Answer

14 + 3 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?