1

I'm trying to do a system that compare an specific date ($date) with the atual date (date('Y/m/d')), but I need to color this $date when he is one week to the atual date (near the maturity date). I don't know if you can understand me, my english is bad...

Thank you for reading this.

Paula Fleck
  • 835
  • 11
  • 21

2 Answers2

3

Do it in the MySQL query:

SELECT maturity_date,
       maturity_date < DATE_ADD(NOW(), INTERVAL 1 WEEK) AS near_maturity,
       ...

Then your PHP code can use if ($row['near_maturity') to color the date.

Barmar
  • 741,623
  • 53
  • 500
  • 612
  • I'm sorry, I didn't find out how to use it. I tryed: ` ` I just don't know how to use it... If I do an echo in `near_maturity`, he displays '1'... – Paula Fleck Oct 23 '13 at 18:38
  • `//code here` should be whatever you want to do to color the output, like `echo '';` – Barmar Oct 23 '13 at 18:39
  • Yes, I put the color code, but he paints the '1'... I want he paints the right date, the date in the database. I tryed like this: ` `. He displays '1' red. – Paula Fleck Oct 23 '13 at 18:46
  • You should echo `$result['date']`, not `$result['near_maturity']`. – Barmar Oct 23 '13 at 18:48
1

Something like this may work:

date_default_timezone_set('America/Los_Angeles');
$date = DateTime::createFromFormat('m-d-Y', '04-15-2013');
$maturityDate = DateTime::createFromFormat('m-d-Y', '04-20-2013');
$maturityDateMinus10Days = DateTime::createFromFormat('m-d-Y', '04-10-2013');

if ($date > $maturityDateMinus10Days
    && $date < $maturityDate) {
    echo 'date is within 10 days of maturity 10';
}

You can test it by copying and pasting here http://writecodeonline.com/php/

Ref. PHP - add 1 day to date format mm-dd-yyyy

Ref. How can I check if the current date/time is past a set date/time?

Community
  • 1
  • 1
user1477388
  • 20,790
  • 32
  • 144
  • 264