Need help with conditional formatting of table rows...

What i need to acheave is to change table row background in red if date_needed is <= than 48 hours than now().

This is what i have now

if (date('d',strtotime($data['date_needed'])) <= 2) $row["rowstyle"]='style="background:red"';

it works in a way... It changes background color for 1. and 2. of the month, but that is not what i need...

Must mark rows where dedline is less or equal to 48 hours.

Thank you!

Recommended Answers

All 4 Replies

I put together a working example of using time() to convert datetime's into integar's:

$now = time();
$testTimes = array('test 1'=>time()+(60*60*16),'test 2'=>time()+(60*60*24*6),'test 3'=>time()-60*30);//test times - array(16 hours,6 days, 30 minutes ago);
//$timetocheck = strtotime('2012-01-18 13:25:12');//to convert a string date or datetime into a time integar

$triggerTime = 60*60*24*2;//seconds * minutes * hours * days(48 hours);

foreach($testTimes as $key=>$value){//$value = time to check
    if($now+$triggerTime > $value){
        if($now > $value){
            echo "{$key} (".date("Y-m-d H:i:s",$value).") Time has already passed<br/>\r\n";
            echo "{$key} (".date("Y-m-d H:i:s",$value).") is in the trigger time band<br/>\r\n";
        echo "{$key} (".date("Y-m-d H:i:s",$value).") is later than the trigger time<br/>\r\n";

time() basically returns the number of seconds that have passed since 1st jan 1970, so you can compare/edit dates in seconds very well, then date() will convert it back into a readable datetime format


Member Avatar

You may want to test this around leap year days and when daylight saving occurs.

Thank you all! I started to use some program but it has some weird language structure. Anyways, i found the solution to suite my needs.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.