How does PHP get the number of days difference between two dates?

Source: Internet
Author: User
Tags date1 getdate

How does PHP get the number of days difference between two dates?  

We often need to get the number of days between two dates to make it easier for customers to know how many days are different from a certain time period, so the results are now becoming more and more popular. No longer shows the date as stiff as it used to be. We've shared here two ways to get the number of days between two dates.

The first type:

01 <?php
02 functioncount_days($a,$b){
03     $a_dtgetdate($a);
04     $b_dtgetdate($b);
"    ;    $a _new  =&NBSP; mktime $a _dt [ ' Mon ' ],  $a _dt [ ' mday ' ],&NBSP; $a _dt [ ' year ' );
"    ;    $b _new  =&NBSP; mktime $b _dt [ ' Mon ' ],  $b _dt [ ' mday ' ],&NBSP; $b _dt [ ' year ' );
07     returnround(abs($a_new-$b_new)/86400);
08 }
09
10 //今天与2008年10月11日相差多少天
11 $date1strtotime(time());
12 $date2strtotime(‘10/11/2008‘);
13 $result= count_days($date1$date2);
14 echo$result;
15 ?>

The second type:

1 <?php
2 //今天与2008年9月9日相差多少天
3 $Date_1date("Y-m-d");
4 $Date_2"2008-10-11";
5 $d1strtotime($Date_1);
6 $d2strtotime($Date_2);
7 $Daysround(($d2-$d1)/3600/24);
8 echo"今天与2008年10月11日相差" $Days"天";
9 ?>

How does PHP get the number of days difference between two dates?

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.