Esempio n. 1
0
/* DOCS
http://php.net/manual/en/function.strtotime.php 
http://php.net/manual/en/function.date.php 
*/
echo '<br />';
/* now with functions... */
function addDays($date, $format, $days)
{
    return date($format, strtotime($date . "+" . $days . " days"));
}
function addMonths($date, $format, $months)
{
    return date($format, strtotime($date . "+" . $months . " months"));
}
function formatDate($date, $format)
{
    return date($format, strtotime($date));
}
$format = 'Y-m-d';
$date = "2016-02-22";
$date = addDays($date, $format, 4);
$date = addMonths($date, $format, 3);
echo formatDate($date, 'd/m/Y');
/* = thousands of tedious heavy-parametrized functions catalog, one for every problem to solve...*/
/* good luck finding the one you need */
/*now with objects...*/
$date = new MyDate("2016-02-22", 'Y-m-d');
$date->addDays(4);
$date->addMonths(3);
echo $date->format('d/m/Y');
/* perfectly understandable code, well organized (every object has its own set of functions)  */