Return to Snippet

Revision: 68895
at March 12, 2015 05:56 by snstro


Updated Code
// Mandatory to set the default timezone to work with DateTime functions
date_default_timezone_set('America/Sao_Paulo');

$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
}

Revision: 68894
at March 12, 2015 05:54 by snstro


Initial Code
// Mandatory to set the default timezone to work with DateTime functions
date_default_timezone_set('America/Sao_Paulo');

$period = new DatePeriod(
	new DateTime('2010-10-01'), // 1st PARAM: start date
	new DateInterval('P1D'), // 2nd PARAM: interval (1 day interval in this case)
	new DateTime('2010-10-05'), // 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
}

Initial URL

                                

Initial Description
Show a list of days between two dates, using native php DateTime functions

Initial Title
Show a list of days between two dates

Initial Tags
php

Initial Language
PHP