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.
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.
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?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.