Php method for obtaining all dates between the start and end dates. php date
This example describes how to obtain all dates between the start and end dates in php. We will share this with you for your reference. The details are as follows:
/*** Get the Date of each day in the specified Date segment * @ param Date $ startdate start Date * @ param Date $ enddate end Date * @ return Array */function getDateFromRange ($ startdate, $ enddate) {$ stimestamp = strtotime ($ startdate); $ etimestamp = strtotime ($ enddate ); // calculate the number of days in the date segment $ days = ($ etimestamp-$ stimestamp)/86400 + 1; // Save the daily date $ date = array (); for ($ I = 0; $ I <$ days; $ I ++) {$ date [] = date ('Y-m-d ', $ stimestamp + (86400 * $ I);} return $ date;} $ startdate = '2017-08-29 '; $ enddate = '2017-09-29 '; // demo $ date = getDateFromRange ($ startdate, $ enddate); print_r ($ date );
The running result is as follows:
Array([0] => 2016-08-29[1] => 2016-08-30[2] => 2016-08-31[3] => 2016-09-01[4] => 2016-09-02[5] => 2016-09-03[6] => 2016-09-04[7] => 2016-09-05[8] => 2016-09-06[9] => 2016-09-07[10] => 2016-09-08[11] => 2016-09-09[12] => 2016-09-10[13] => 2016-09-11[14] => 2016-09-12[15] => 2016-09-13[16] => 2016-09-14[17] => 2016-09-15[18] => 2016-09-16[19] => 2016-09-17[20] => 2016-09-18[21] => 2016-09-19[22] => 2016-09-20[23] => 2016-09-21[24] => 2016-09-22[25] => 2016-09-23[26] => 2016-09-24[27] => 2016-09-25[28] => 2016-09-26[29] => 2016-09-27[30] => 2016-09-28[31] => 2016-09-29)