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

Source: Internet
Author: User
Tags getdate

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:

<?phpfunction count_days ($a, $b) {$a _dt = getdate ($a); $b _dt = getdate ($b); $a _new = mktime (0, 0, $a _dt[' mon '), $a _dt[ ' Mday '], $a _dt[' year '); $b _new = mktime (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 $date1 = Strtotime (Time ()), $date 2 = strtotime (' 10/11/2008 '); $result = Count_days ($date 1, $date 2) ; Echo $result;? >

The second type:

<?php//today differs from September 9, 2008 by how many days $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. "Day";? >

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

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.