dongsheng4679 2016-09-29 09:38
浏览 15
已采纳

如何在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.

  • 写回答

4条回答 默认 最新

  • dqwh1202 2016-09-29 09:48
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源