Date Cell Conditional Format

QuestionsDate Cell Conditional Format
Tom asked 10 years ago

I have a mySQL database field, 'dischargeDate', with the type of 'date', and dates stored in the field like this: '2014-07-01' and '2013-12-23'

I'm displaying that date in the grid.

I would like to highlight the 'dischargeDate' cell WHEN the dischargeDate is less then 2014-06-01

I have this code in my grid config:

$f = array();
$f["column"] = "dischargeDate";
$f["op"] = "<";
$f["value"] = "2014-06-01";
$f["cellcss"] = "'background-color':'red'";
$f_conditions[] = $f;

This code does not highlight either: '2014-07-01' and '2013-12-23'

if I change it to: ">" it highlights BOTH: '2014-07-01' and '2013-12-23'

How do I compare date cells?

-Tom

1 Answers
Abu Ghufran answered 10 years ago

This comparison is done on clientside (via js) so first we need to convert date format to a numeric value.
e.g.

in sql: date_format(invdate,'%Y%m%d') as invdate_calc

Now, make a hidden column to hold this formatted date.

$col = array();
$col["title"] = "Date Calc";
$col["name"] = "invdate_calc"; // sql aliased column of invdate with date format (20120101)
$col["width"] = "20";
$col["editable"] = false; // this column is editable
$col["hidden"] = true; // this column is hidden, just used for formatting
$col["search"] = false;
$cols[] = $col;

And then use this column in conditional formatting:

// If date is > than 20120101, highlight row with red
$f = array();
$f["column"] = "invdate_calc";
$f["op"] = ">";
$f["value"] = "20120101";
$f["class"] = "focus-row";
$f_conditions[] = $f;

Complete demo is located in demos/appearance/conditional-format.php

Your Answer

14 + 2 =

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?