PHP Date Difference days processing function

Source: Internet
Author: User
Tags getdate

When we develop, we often encounter to add a time to another time minus is it, I would like to recommend two PHP date difference days processing function.

First type:
<?php
function count_days ($a, $b) {
$a _dt=getdate ($a);
$b _dt=getdate ($b);
$a _new=mktime (12,0,0, $a _dt[' mon '), $a _dt[' mday '], $a _dt[' year ']);
$b _new=mktime (12,0,0, $b _dt[' mon '), $b _dt[' Mday '], $b _dt[' year ']);
Return round (ABS ($a _new-$b _new)/86400);
}
Today and October 11, 2008 How many days difference
$date 1=strtotime (Time ());
$date 1=strtotime (' 10/11/2008 ');
$result =count_days ($date 1, $date 2);
echo $result;
?>


The second type:
<?php
Today and September 9, 2008 How many days difference
$Date _1=date ("y-m-d");
$Date _2= "2008-10-11";
$d 1=strtotime ($Date _1);
$d 2=strtotime ($Date _2);
$Days =round (($d 2-$d 1)/3600/24);
echo "Today differs from October 11, 2008". $Days. " Days ";
?>

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.