当前位置:Gxlcms > PHP教程 > php计算到指定日期还有多少天的方法_php技巧

php计算到指定日期还有多少天的方法_php技巧

时间:2021-07-01 10:21:17 帮助过:19人阅读

本文实例讲述了php计算到指定日期还有多少天的方法。分享给大家供大家参考。具体如下:

  1. function countdays($d)
  2. {
  3. $olddate = substr($d, 4);
  4. $newdate = date(Y) ."".$olddate;
  5. $nextyear = date(Y)+1 ."".$olddate;
  6. if($newdate > date("Y-m-d"))
  7. {
  8. $start_ts = strtotime($newdate);
  9. $end_ts = strtotime(date("Y-m-d"));
  10. $diff = $end_ts - $start_ts;
  11. $n = round($diff / 86400);
  12. $return = substr($n, 1);
  13. return $return;
  14. }
  15. else
  16. {
  17. $start_ts = strtotime($nextyear);
  18. $end_ts = strtotime(date("Y-m-d"));
  19. $diff = $end_ts - $start_ts;
  20. $n = round($diff / 86400);
  21. $return = substr($n, 1);
  22. return $return;
  23. }
  24. }

希望本文所述对大家的php程序设计有所帮助。

人气教程排行