PHP loop - add days to date -
I have the following code, though this works to add a date (between days) to a date (startup) Until I reach the end date, I will repeat it. How can i do this
$ startDate = "2009-10-11"; $ EndDate = "2010-01-20"; Between $ days = 10; Function addDayswithdate ($ date, $ day) {$ date = strtotime ("+". $ Day. "Day", stratetime ($ date)); Return date ("Y-M-D", $ date); } $ Date = addDayswithdate ($ startDate, $ daysBetween);
You can use the following function;
& lt ;; Php $ startDate = "2009-10-11"; $ EndDate = "2010-01-20"; Between $ days = 10; $ FinalResult = array (); Function addDayswithdate ($ date, $ day, $ endDate, and $ last result) {$ tempDate = strtotime ($ date); $ TempDate + = 3600 * 24 * $ day; If ($ tempDate & lt; strtotime ($ endDate)) {$ finalResult [] = Date ("Y-M-D", $ tempDate); AddDayswithdate (date ("Y-M-D", $ tempDate), $ day, $ endDate, $ finalResult); } And {return true; }} AddDayswithdate ($ startDate, $ daysBetween, $ endDate, $ finalResult); var_dump ($ finalResult); Here is an active demo:
Comments
Post a Comment