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条)

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料