Compare two dates for a few days

Source: Internet
Author: User
Tags explode

There are times when we need to know the difference between two dates, such as the calculation of the article from the date of release to the current average number of clicks, the following example provides a good idea

? Php
$Date _1= "2003-7-15";//format can also be: $Date _1= "2003-6-25 23:29:14";
$Date _2= "1982-10-1";
$Date _list_1=explode ("-", $Date _1);
$Date _list_2=explode ("-", $Date _2);
$d 1=mktime (0,0,0, $Date _list_1[1], $Date _list_1[2], $Date _list_1[0]);
$d 2=mktime (0,0,0, $Date _list_2[1], $Date _list_2[2], $Date _list_2[0]);
$Days =round (($d 1-$d 2)/3600/24);
Echo "I have struggled for $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.