3v4l.org

run code in 300+ PHP versions simultaneously
<?php $days = []; $searchData = ['dat' => '2015-11-11']; $offset = 3; $now = date_create(); $offsetStart = -1 * $offset; echo date_create($searchData['dat'])->modify($offsetStart .' days')->format('Y-m-d H:i'); echo PHP_EOL . $now->format('Y-m-d H:i:s'); echo PHP_EOL . date_create($now)->diff($searchData['dat'])->days; if (date_create($searchData['dat'])->modify($offsetStart .' days') < $now) { $offsetStart = -1 * date_create($searchData['dat'])->diff($now)->days; } $offsetEnd = 2 * $offset + $offsetStart; for ($i = $offsetStart; $i <= $offsetEnd; $i++) { $days[] = $i; } print_r($days);
Output for 8.0.0 - 8.0.12, 8.0.14 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
2015-11-08 00:00 2015-11-10 15:54:39 Fatal error: Uncaught TypeError: date_create(): Argument #1 ($datetime) must be of type string, DateTime given in /in/rCROY:11 Stack trace: #0 /in/rCROY(11): date_create(Object(DateTime)) #1 {main} thrown in /in/rCROY on line 11
Process exited with code 255.
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 2015-11-08 00:00 2015-11-10 15:54:39 Fatal error: Uncaught TypeError: date_create(): Argument #1 ($datetime) must be of type string, DateTime given in /in/rCROY:11 Stack trace: #0 /in/rCROY(11): date_create(Object(DateTime)) #1 {main} thrown in /in/rCROY on line 11
Process exited with code 255.
Output for 8.0.13
2015-11-08 00:00 2015-11-10 14:54:39 Fatal error: Uncaught TypeError: date_create(): Argument #1 ($datetime) must be of type string, DateTime given in /in/rCROY:11 Stack trace: #0 /in/rCROY(11): date_create(Object(DateTime)) #1 {main} thrown in /in/rCROY on line 11
Process exited with code 255.
Output for 7.3.16 - 7.3.31, 7.4.0 - 7.4.33
2015-11-08 00:00 2015-11-10 15:54:39 Warning: date_create() expects parameter 1 to be string, object given in /in/rCROY on line 11 Fatal error: Uncaught Error: Call to a member function diff() on bool in /in/rCROY:11 Stack trace: #0 {main} thrown in /in/rCROY on line 11
Process exited with code 255.
Output for 7.3.32 - 7.3.33
2015-11-08 00:00 2015-11-10 14:54:39 Warning: date_create() expects parameter 1 to be string, object given in /in/rCROY on line 11 Fatal error: Uncaught Error: Call to a member function diff() on bool in /in/rCROY:11 Stack trace: #0 {main} thrown in /in/rCROY on line 11
Process exited with code 255.
Output for 7.0.0 - 7.0.31, 7.1.0 - 7.1.2, 7.1.4 - 7.1.23, 7.2.0 - 7.2.33
2015-11-08 00:00 2015-11-10 15:54:39 Warning: date_create() expects parameter 1 to be string, object given in /in/rCROY on line 11 Fatal error: Uncaught Error: Call to a member function diff() on boolean in /in/rCROY:11 Stack trace: #0 {main} thrown in /in/rCROY on line 11
Process exited with code 255.
Output for 7.1.3

Process exited with code 137.
Output for 5.6.0 - 5.6.38
2015-11-08 00:00 2015-11-10 15:54:39 Warning: date_create() expects parameter 1 to be string, object given in /in/rCROY on line 11 Fatal error: Call to a member function diff() on boolean in /in/rCROY on line 11
Process exited with code 255.
Output for 5.5.0 - 5.5.38
2015-11-08 00:00 2015-11-10 15:54:39 Warning: date_create() expects parameter 1 to be string, object given in /in/rCROY on line 11 Fatal error: Call to a member function diff() on a non-object in /in/rCROY on line 11
Process exited with code 255.

preferences:
224.4 ms | 402 KiB | 286 Q