Code to calculate how many days and hours the PHP time difference is

WBOY
Release: 2016-07-25 08:58:40
Original
1661 people have browsed it
  1. /**

  2. * Calculate the difference in days and hours
  3. * edit bbs.it-home.org
  4. */
  5. function DateDiff($startDay,$endDay){
  6. $start=strtotime($startDay);
  7. $end=strtotime( $endDay);
  8. $diff=abs($start-$end);
  9. $day='';
  10. $vals=array('day'=>'86400','hour'=>'3600', 'Minutes'=>'60','Seconds'=>'1');
  11. foreach($vals as $key=>$value){
  12. if($diff>=$value){
  13. $d =round($diff/$value);
  14. $diff%=$value;
  15. $day.=$d.$key;
  16. }
  17. }
  18. return $day;
  19. }

  20. //Call example

  21. echo "Programmer's Home, remind you that it is still far from 24:00 on February 1, 2014:"
  22. echo DateDiff(date("Y-m-d H:i:s",mktime()),"2014 -02-01 23:59:59");
  23. ?>

Copy code


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!