Home >Backend Development >PHP Tutorial >PHP function to calculate the number of days difference between two dates

PHP function to calculate the number of days difference between two dates

WBOY
WBOYOriginal
2016-07-25 08:54:081490browse
  1. /*
  2. *
  3. *Function function: Calculate the difference of two dates in YYYY-MM-DD format by how many days
  4. *
  5. */
  6. function getChaBetweenTwoDate($date1,$date2 ){
  7. $Date_List_a1=explode("-",$date1);
  8. $Date_List_a2=explode("-",$date2);
  9. $d1=mktime(0,0,0,$Date_List_a1[1 ],$Date_List_a1[2],$Date_List_a1[0]);

  10. $d2=mktime(0,0,0,$Date_List_a2[1],$Date_List_a2[2],$Date_List_a2[0]);
  11. $Days= round(($d1-$d2)/3600/24);
  12. return $Days;
  13. }

  14. echo getChaBetweenTwoDate('2010-08-11','2010-08-16' );

  15. echo "
    ";
  16. echo getChaBetweenTwoDate('2010-08-16','2010-08-11');
  17. ?>

Copy code


Statement:
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