fork download
  1. <?php
  2.  
  3. $date = date_create('2014-05-09');
  4.  
  5. addInterval( $date, '10 days'); // 10 дней
  6. addInterval( $date, '5 weeks'); // 5 недель
  7. addInterval( $date, '1 month'); // 1 месяц
  8. addInterval( $date, '2 years'); // 2 года
  9.  
  10. function addInterval( $date, $interval){
  11. $newDate = clone $date;
  12. date_add($newDate, date_interval_create_from_date_string( $interval));
  13. printf( "%s + \"%s\" = %s\n",
  14. date_format($date, 'Y-m-d'),
  15. $interval,
  16. date_format($newDate, 'Y-m-d')
  17. );
  18. }
  19.  
  20.  
Success #stdin #stdout 0.01s 20520KB
stdin
Standard input is empty
stdout
2014-05-09 + "10 days" = 2014-05-19
2014-05-09 + "5 weeks" = 2014-06-13
2014-05-09 + "1 month" = 2014-06-09
2014-05-09 + "2 years" = 2016-05-09