eval.in

Paste #716901

PHP — PHP 5.6.23, pasted 5 months ago

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
<?php

$dt = new DateTime('first Monday of jan 2017');

$interval = new DateInterval('P1W');
$next_week = $dt->add($interval);
echo $next_week->format('Y-m-d');

echo "\n";
$dt = new DateTime('first Tuesday of jan 2017');
$interval = new DateInterval('P2W');
$next_week = $dt->add($interval);
echo $next_week->format('Y-m-d');

Program Output

2017-01-09
2017-01-17

OK (0.008 sec real, 0.008 sec wall, 14 MB, 46 syscalls)

Fork