3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function add_weeks($weeks = 1, $base = 'now') { // treat non-strings as a unix timestamp if (!is_string($base)) { $base = '@' . intval($base); } return strtotime(sprintf('%s +%d weeks', $base, $weeks)); } echo date('Y-m-d', add_weeks()) . "\n"; echo date('Y-m-d', add_weeks(2)) . "\n"; echo date('Y-m-d', add_weeks(1, time() + 86400)) . "\n"; echo date('Y-m-d', add_weeks(1, '2012-06-05')) . "\n"; $oneWeek = add_weeks(1, 'now'); if (date('j', $oneWeek) < date('j')) { $oneWeek = strtotime('last day of this month'); } echo date('Y-m-d', $oneWeek) . "\n";
Output for 5.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
2014-04-04 2014-04-11 2014-04-05 2012-06-12 2014-03-31
Output for 5.1.0 - 5.2.17
2014-04-04 2014-04-11 2014-04-05 2012-06-12 1970-01-01
Output for 4.3.0 - 5.0.5
2014-04-04 2014-04-11 1970-01-01 2012-06-12 1970-01-01