php - basic date comparsion for expiration checking -


i want create traffic lights system tell me how many days left go until document reaches expiration date. want marked colors in html.

  • green: if document has 31 days or more go until expires.
  • amber: 30 days or less until expires.
  • red: 7 days or less.

i want display text, telling me how many days until expiration. expiration date comes database in field called insurance_date

heres code new php struggling put code together, if show me how restructure code in order achieve im trying id greatful, thanks.

my code:

 <?php      include 'config.php';    $data = mysql_query("select * supplier_stats")     or die(mysql_error());      while($info = mysql_fetch_array( $data ))     {       echo "<p>insurance expires ! - <font color=\"red\">".$info['insurance_date'] . "</font></p>";      }      $date_diff = 60*60*24*7; // 7 days    // time()+$date_diff timestamp 7 days in future    if ($info['insurance_date'] < time()+$date_diff) {     echo "less 7 days left!";    } 

in while loop, iterate on entries in supplier_stats table. every iteration, output "<p>insurance expires ! .... not want that. edit query select entries expire within range.

example:

select * supplier_stats insurance_date >= yourdatetocompareto 

depending on how did set database, insurance_date may of 'mysql type date or string or integer. depending on that, have make comparsion check if date close expiration range.

after loop (closed }) still use $info in if ($info['insurance_date'] use last entry in table.

this very, basic question , i'd advise read on basic beginners tutorials can found using internet search engine.


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -