PHP Date distance How many days

Source: Internet
Author: User
Tags diff

Meet a demand, to calculate the day after the start of the activity ~

Scenario One: Date_diff () function, but requires PHP version 5.3+

$date 1=date_create ("2015-11-02"));$date 2=date_create (Date(' y-m-d ', Time()));$diff=date_diff ($date 1,$date 2);$has _start=$diff->days + 1;Echo $count _day= 10000 *POW($has _start, 2);Var_dump($diff);//Echo $diff->format ("%r%a days");

Scenario Two: Strtotime (), all versions available, but 2035 is a hurdle, int type overflow problem

$start _day= "2015-11-04";$cur _day=Date(' y-m-d ', Time());$start _time=Strtotime($start _day);$cur _time=Strtotime($cur _day);$diff=$cur _time-$start _time;$diff _day=Ceil($diff/3600/24) + 1;$d=Ceil($diff/3600/24);$h=Ceil($diff% (3600/24)/3600);$m=Ceil($diff% (3600/24)/60);Echo"Difference$d days $h hours $m minutes";

PHP Date distance How many 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.