/ Published in: PHP
Show a list of days between two dates, using native php DateTime functions
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
// Mandatory to set the default timezone to work with DateTime functions $start_date = new DateTime('2010-10-01'); $end_date = new DateTime('2010-10-05'); $period = new DatePeriod( $start_date, // 1st PARAM: start date new DateInterval('P1D'), // 2nd PARAM: interval (1 day interval in this case) $end_date, // 3rd PARAM: end date DatePeriod::EXCLUDE_START_DATE // 4th PARAM (optional): self-explanatory ); foreach($period as $date) { echo $date->format('Y-m-d').'<br/>'; // Display the dates in yyyy-mm-dd format }