Jump to content

Super Simple Date Problem


pauldavidbrown

Recommended Posts

I'm sure this is super simple, I just can't figure it out.  I have a php page that accesses a mysql database and shows the date closed.  I simply want the page to display the  date in black by default, green if 30-60 days past (from current date), orange if 60-90, and red if over 90.  The Structure of the CloseDate field is just a date field within mysql.

 

This runs on a bluehost server with all current php and mysql versions.

 

Any response is sincerely appreciated.  See attached screen shot.

 

post-191898-0-16378200-1452369200_thumb.jpg

 

  

Link to comment
Share on other sites

Most recently, I have tried this...

 

$Today = date('m/d/Y');
$Days = date_diff($Today, $row('CloseDate')); 
echo $Days->format('%R%a days');
 
But -- I cannot get it to even display the # of days in that format and am therefore stuck.
 
I'm guessing it is because the two are not in the same date format.  I've also tried $Today = new DateTime("now");  -- but it yields the same results.
Edited by pauldavidbrown
Link to comment
Share on other sites

here's an example

<?php
$dates = [      '2015-09-12',
                '2015-10-15',
                '2015-11-23',
                '2015-12-08',
                '2015-12-28'
                ];
$now = new DateTime();
$tdata = '';
foreach ($dates as $dt) {
    $closed = new DateTime($dt);
    $age = $now->diff($closed)->days;
    $dateout = $closed->format('m/d/Y');
    
    if ($age > 90) {
        $class = 'over90';
    }
    elseif ($age > 60) {
        $class = 'over60';
    }
    elseif ($age > 30) {
        $class = 'over30';
    }
    else $class = 'default';
    
    $tdata .= "<tr><td class='$class'>$dateout</td></tr>";
}
?>
<html>
<head>
<title>Example</title>
<style type='text/css'>
td.default {color: black;}
td.over30  {background-color: green; color: white;}
td.over60  {background-color: orange; color: white;}
td.over90  {background-color: red; color: white;}
</style>
</head>
<body>
    <table>
        <?=$tdata?>
    </table>
</body>
</html>
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.