PHP gets all dates between the start date and the end date

Source: Internet
Author: User
Due to project requirements, data from the specified date period needs to be processed on a daily basis.

For example, the data for each day of the date period from 2016-06-01 to 2016-06-05 needs to be processed. First you need to get the date of each day in this date period, and then loop through the processing.


    
     $date = array('2016-06-01','2016-06-02','2016-06-03','2016-06-04','2016-06-05');foreach($dateas$d){    // 执行处理}?>

If the date period spans large (2015-09-01 to 2016-06-30) and there are cross-year, cross-month (leap months) situations, the manual creation date array is too time-consuming and unreasonable.

As a result, you can get the date of each day in the specified date period by writing the following code:

 
       /** * Gets the date of each day in the specified date period * @param Date $startdate start date * @param Date $enddate End Date * @ret Urn Array *
  / functiongetdatefromrange($startdate, $enddate){$stimestamp= Strtotime ($startdate);$etimestamp= Strtotime ($enddate);//Calculate how many days in a date period$days= ($etimestamp-$stimestamp)/86400+1;//Save daily date$date=Array(); for($i=0;$i<$days;$i++){$date[] = Date (' y-m-d ',$stimestamp+(86400*$i)); }return$date;}//Demo$date= Getdatefromrange (' 2016-02-25 ',' 2016-03-05 ');p Rint_r ($date);?>

Output:

Array(    [02016-02-25    [12016-02-26    [22016-02-27    [32016-02-28    [42016-02-29    [52016-03-01    [62016-03-02    [72016-03-03    [82016-03-04    [92016-03-05)

'). addclass (' pre-numbering '). Hide (); $ (this). addclass (' has-numbering '). Parent (). append ($numbering); for (i = 1; i <= lines; i++) {$numbering. Append ($ ('
  • '). Text (i)); }; $numbering. FadeIn (1700); }); });

    The above describes the PHP get start date and end date of all dates, including aspects of the content, I hope to be interested in PHP tutorial friends helpful.

  • Related Article

    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.