PHP Date processing rollup, specifying the date plus and minus days, looping two dates between the specified dates

Source: Internet
Author: User
Tags diff

One.

(1) How many days to add or subtract the specified date

(2) cycle the date between two specified dates

Cases:

$start _time = ' 2017-07-01 ';
$end _time = ' 2017-07-10 ';

Get time difference

$diff = Strtotime ($end _time)-strtotime ($start _time);
$num = $diff/(24*60*60) +1;

for ($i =0; $i < $num; $i + +) {
$selectTime = Date ("y-m-d", Strtotime ("$end _time-$i Days"); Focus, specify the date plus and minus how many days
echo $selectTime. ' <br> ';
}

Output:

2017-07-10
2017-07-09
2017-07-08
2017-07-07
2017-07-06
2017-07-05
2017-07-04
2017-07-03
2017-07-02
2017-07-01

PHP Date processing rollup, specifying the date plus and minus days, looping two dates between the specified 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.