1. Go to this page and download the library: Download rundiz/date-interval library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
rundiz / date-interval example snippets
$date_begins = '2018-08-01';
$date_end = '2018-12-31';
$interval_num = 10;
$interval_unit = 'D';
$DateInterval = new \Rundiz\DateInterval\DateInterval();
$DateInterval->date_begins = $date_begins;
$DateInterval->date_end = $date_end;
$DateInterval->setInterval($interval_num, $interval_unit);
$list_dates = $DateInterval->getTheDates();
if ($list_dates == false || !is_array($list_dates)) {
echo "\t".'<h3>Error!</h3>'."\n";
// Displaying the error messages from class.
foreach ($DateInterval->getErrorMessage() as $err_msg) {
echo "\t\t".$err_msg.'<br>'."\n";
}
// Or!! if you want to use your custom error message, translation please use the code below instead.
/*foreach ($DateInterval->getErrorCodes() as $err_code) {
// for more, please read the docblock at `getErrorCodes()` method.
switch ($err_code) {
case 'RDDINTV_NO_DATE_BEGINS':
echo 'There is no begins date or invalid format.<br>'."\n";
break;
case 'RDDINTV_INCORRECT_DATE_BEGINS':
echo 'The begins date value is incorrect.<br>'."\n";
break;
case 'RDDINTV_NO_INTERVAL_RANGE':
echo 'Please enter interval or range in <code>setInterval()</code> method.<br>'."\n";
break;
default:
echo 'Unknow error!<br>'."\n";
break;
}
}*/
} else {
foreach ($list_dates as $each_date) {
echo "\t".$each_date.'<br>'."\n";
}
}