如何在php中关闭日期即将到期[关闭]

I asked "How to determin date below todays date from db in php" in my last post and it was helpful. Now i need help on how to alert administrator when drugs date in db remain 60 day to expire. todays date is date('Y-m-d') and from db I have 2016-12-20.

DB sample

+----+----------+--------+------------+
| id | drug_nam | amount |    exp     |
+----+----------+--------+------------+
| 1  | M and T  |    200 | 2018-02-10 |
| 2  | VIT C    |     20 | 2016-12-30 |
| 3  | Pana     |     10 | 2017-01-18 |
| 4  | Lonat    |   1200 | 2018-02-20 |
| 5  | ProC     |    100 | 2017-06-10 |
+----+----------+--------+------------+

please I need way out on how I can count date remain 60 day to expire using mysqli.

you can check this datediff tutorial

<?php
   $date_now = date_create(date('Y-m-d'));
   $date_db = date_create('2018-02-10');

   $date_diff = date_diff($date_now,$date_db);
   echo '<pre>';
   print_r($date_diff);
   echo '</pre>';
?>
and the result is ..
DateInterval Object
(
   [y] => 1
   [m] => 4
   [d] => 12
   [h] => 0
   [i] => 0
   [s] => 0
   [weekday] => 0
   [weekday_behavior] => 0
   [first_last_day_of] => 0
   [invert] => 0
   [days] => 499
   [special_type] => 0
   [special_amount] => 0
   [have_weekday_relative] => 0
   [have_special_relative] => 0
)

you can check code above here

$date_diff is an object DateInterval. you can take the days by $date_diff->d.

if($date_diff->d < 60)echo 'less than 60 days';

I hope it help you

Try this:

Where you are showing the list of these drugs make an expire column and calculate the expiry date like:

$futureDate = date('Y-m-d', strtotime("+60 days"));
// It will return the date of 60 days + todays date

Put a check if

$futureDate >= drug expire date, than drug is expired.

This is not tested. You can try:

$sixtyDays = date('Y-m-d', strtotime('+60 days'));
$dbDate = '2016-12-20';

if (strtotime($dbDate) <= strtotime($sixtyDays)) {
    // db date is 60 days or less than 60 days from today
}

This will return those data where 60 days to expire SELECT DATE_ADD(exp,INTERVAL 60 day) > now() from <tblname>