3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function getIntervalEnd($pointer, $interval){ $to = clone $pointer; // For minute interval, return end of the pointers minute if($interval == 'PT1M') $to->setTime($to->format('H'), $to->format('i'), 59); // For hour interval, return end of the pointers hour elseif($interval == 'PT1H') $to->setTime($to->format('H'), 59, 59); // For day interval, return end of the pointers day elseif($interval == 'P1D') $to->setTime(23, 59, 59); // For week interval, return end of the pointers week elseif($interval == 'P7D'){ if($to->format('N') != 7) $to->setTimestamp(strtotime('next sunday', $to->getTimestamp())); $to->setTime(23, 59, 59); } // For month interval, return end of the pointers month elseif($interval == 'P1M') $to->setDate($to->format('Y'), $to->format('m'),$to->format('t'))->setTime(23, 59, 59); // For year interval, return end of the pointers year elseif($interval == 'P1Y') $to->setDate($to->format('Y'), 12, 31)->setTime(23, 59, 59); return $to; } echo getIntervalEnd(new \DateTime(), 'P1D')->format('c');
Output for 5.3.0 - 5.4.41, 5.6.28, 7.0.20 - 7.3.0beta1
2015-06-05T23:59:59+02:00
Output for 7.0.6
2016-05-03T23:59:59+02:00
Output for 7.0.5
2016-04-02T23:59:59+02:00
Output for 7.0.4
2016-03-09T23:59:59+01:00
Output for 7.0.3
2016-03-17T23:59:59+01:00
Output for 7.0.2
2016-03-21T23:59:59+01:00
Output for 7.0.1
2016-03-23T23:59:59+01:00
Output for 7.0.0
2016-03-26T23:59:59+01:00
Output for 5.6.21
2016-05-01T23:59:59+02:00
Output for 5.6.20
2016-04-09T23:59:59+02:00
Output for 5.6.19
2016-03-06T23:59:59+01:00
Output for 5.6.18
2016-03-14T23:59:59+01:00
Output for 5.6.17
2016-03-19T23:59:59+01:00
Output for 5.6.16
2016-03-27T23:59:59+02:00
Output for 5.6.15
2016-03-28T23:59:59+02:00
Output for 5.6.14
2016-04-01T23:59:59+02:00
Output for 5.6.13
2016-04-14T23:59:59+02:00
Output for 5.6.12
2016-04-19T23:59:59+02:00
Output for 5.6.11
2016-04-22T23:59:59+02:00
Output for 5.6.10
2016-04-24T23:59:59+02:00
Output for 5.6.9
2016-04-27T23:59:59+02:00
Output for 5.6.8
2016-04-29T23:59:59+02:00
Output for 5.6.7
2016-05-24T23:59:59+02:00
Output for 5.5.35
2016-05-21T23:59:59+02:00
Output for 5.5.34
2016-04-10T23:59:59+02:00
Output for 5.5.33
2016-03-08T23:59:59+01:00
Output for 5.5.32
2016-03-15T23:59:59+01:00
Output for 5.5.31
2016-03-20T23:59:59+01:00
Output for 5.5.30
2016-03-31T23:59:59+02:00
Output for 5.5.29
2016-04-16T23:59:59+02:00
Output for 5.5.28
2016-04-20T23:59:59+02:00
Output for 5.5.27
2016-04-21T23:59:59+02:00
Output for 5.5.26
2016-04-25T23:59:59+02:00
Output for 5.5.25
2016-04-28T23:59:59+02:00
Output for 5.5.24
2016-04-30T23:59:59+02:00
Output for 5.4.43 - 5.4.45
2015-09-22T23:59:59+02:00
Output for 5.4.42
2015-06-28T23:59:59+02:00
Output for 5.2.0 - 5.2.17
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/PLnhj on line 39 2015-06-05T23:59:59+02:00
Output for 5.0.0 - 5.1.6
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/PLnhj on line 39 Fatal error: Class 'DateTime' not found in /in/PLnhj on line 39
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_VARIABLE in /in/PLnhj on line 6
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_VARIABLE in /in/PLnhj on line 6
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/PLnhj on line 6
Process exited with code 255.