3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $days = []; $searchData = ['dat' => '2015-11-10']; $offset = 3; $now = date_create(); $offsetStart = -1 * $offset; echo date_create($searchData['dat'])->modify($offset .' days')->format('Y-m-d H:i'); echo PHP_EOL . $now->format('Y-m-d H:i:s'); echo PHP_EOL . date_create($searchData['dat'])->diff($now)->format('%a'); if (date_create($searchData['dat'])->modify($offset .' days') < $now) { $offsetStart = -1 * date_create($searchData['dat'])->diff($now)->format('%a'); } $offsetEnd = 2 * $offset + $offsetStart; for ($i = $offsetStart; $i <= $offsetEnd; $i++) { $days[] = $i; } print_r($days);
based on bnPDq
Output for 5.6.28, 7.0.20 - 7.2.0
2015-11-13 00:00 2015-11-10 15:50:40 0Array ( [0] => -3 [1] => -2 [2] => -1 [3] => 0 [4] => 1 [5] => 2 [6] => 3 )
Output for 7.0.6
2015-11-13 00:00 2016-05-03 18:37:02 175Array ( [0] => -175 [1] => -174 [2] => -173 [3] => -172 [4] => -171 [5] => -170 [6] => -169 )
Output for 7.0.5
2015-11-13 00:00 2016-04-03 07:01:48 145Array ( [0] => -145 [1] => -144 [2] => -143 [3] => -142 [4] => -141 [5] => -140 [6] => -139 )
Output for 7.0.4
2015-11-13 00:00 2016-03-10 18:49:08 121Array ( [0] => -121 [1] => -120 [2] => -119 [3] => -118 [4] => -117 [5] => -116 [6] => -115 )
Output for 7.0.3
2015-11-13 00:00 2016-03-18 19:58:34 129Array ( [0] => -129 [1] => -128 [2] => -127 [3] => -126 [4] => -125 [5] => -124 [6] => -123 )
Output for 7.0.2
2015-11-13 00:00 2016-03-23 02:06:49 134Array ( [0] => -134 [1] => -133 [2] => -132 [3] => -131 [4] => -130 [5] => -129 [6] => -128 )
Output for 7.0.1
2015-11-13 00:00 2016-03-24 05:44:26 135Array ( [0] => -135 [1] => -134 [2] => -133 [3] => -132 [4] => -131 [5] => -130 [6] => -129 )
Output for 7.0.0
2015-11-13 00:00 2016-03-27 07:40:26 138Array ( [0] => -138 [1] => -137 [2] => -136 [3] => -135 [4] => -134 [5] => -133 [6] => -132 )
Output for 5.6.21
2015-11-13 00:00 2016-05-02 13:46:06 174Array ( [0] => -174 [1] => -173 [2] => -172 [3] => -171 [4] => -170 [5] => -169 [6] => -168 )
Output for 5.6.20
2015-11-13 00:00 2016-04-10 06:01:04 152Array ( [0] => -152 [1] => -151 [2] => -150 [3] => -149 [4] => -148 [5] => -147 [6] => -146 )
Output for 5.6.19
2015-11-13 00:00 2016-03-08 03:00:49 119Array ( [0] => -119 [1] => -118 [2] => -117 [3] => -116 [4] => -115 [5] => -114 [6] => -113 )
Output for 5.6.18
2015-11-13 00:00 2016-03-15 11:44:46 126Array ( [0] => -126 [1] => -125 [2] => -124 [3] => -123 [4] => -122 [5] => -121 [6] => -120 )
Output for 5.6.17
2015-11-13 00:00 2016-03-19 23:23:47 130Array ( [0] => -130 [1] => -129 [2] => -128 [3] => -127 [4] => -126 [5] => -125 [6] => -124 )
Output for 5.6.16
2015-11-13 00:00 2016-03-28 08:27:36 139Array ( [0] => -139 [1] => -138 [2] => -137 [3] => -136 [4] => -135 [5] => -134 [6] => -133 )
Output for 5.6.15
2015-11-13 00:00 2016-03-29 09:18:22 140Array ( [0] => -140 [1] => -139 [2] => -138 [3] => -137 [4] => -136 [5] => -135 [6] => -134 )
Output for 5.6.14
2015-11-13 00:00 2016-04-02 11:09:07 144Array ( [0] => -144 [1] => -143 [2] => -142 [3] => -141 [4] => -140 [5] => -139 [6] => -138 )
Output for 5.6.13
2015-11-13 00:00 2016-04-15 15:33:55 157Array ( [0] => -157 [1] => -156 [2] => -155 [3] => -154 [4] => -153 [5] => -152 [6] => -151 )
Output for 5.6.12
2015-11-13 00:00 2016-04-20 06:03:28 162Array ( [0] => -162 [1] => -161 [2] => -160 [3] => -159 [4] => -158 [5] => -157 [6] => -156 )
Output for 5.6.11
2015-11-13 00:00 2016-04-24 12:26:29 166Array ( [0] => -166 [1] => -165 [2] => -164 [3] => -163 [4] => -162 [5] => -161 [6] => -160 )
Output for 5.6.10
2015-11-13 00:00 2016-04-25 14:28:44 167Array ( [0] => -167 [1] => -166 [2] => -165 [3] => -164 [4] => -163 [5] => -162 [6] => -161 )
Output for 5.6.9
2015-11-13 00:00 2016-04-27 19:38:35 169Array ( [0] => -169 [1] => -168 [2] => -167 [3] => -166 [4] => -165 [5] => -164 [6] => -163 )
Output for 5.6.8
2015-11-13 00:00 2016-04-30 04:30:41 172Array ( [0] => -172 [1] => -171 [2] => -170 [3] => -169 [4] => -168 [5] => -167 [6] => -166 )
Output for 5.5.35
2015-11-13 00:00 2016-05-22 21:14:22 194Array ( [0] => -194 [1] => -193 [2] => -192 [3] => -191 [4] => -190 [5] => -189 [6] => -188 )
Output for 5.5.34
2015-11-13 00:00 2016-04-11 08:13:00 153Array ( [0] => -153 [1] => -152 [2] => -151 [3] => -150 [4] => -149 [5] => -148 [6] => -147 )
Output for 5.5.33
2015-11-13 00:00 2016-03-09 05:45:25 120Array ( [0] => -120 [1] => -119 [2] => -118 [3] => -117 [4] => -116 [5] => -115 [6] => -114 )
Output for 5.5.32
2015-11-13 00:00 2016-03-17 15:40:28 128Array ( [0] => -128 [1] => -127 [2] => -126 [3] => -125 [4] => -124 [5] => -123 [6] => -122 )
Output for 5.5.31
2015-11-13 00:00 2016-03-21 02:26:06 132Array ( [0] => -132 [1] => -131 [2] => -130 [3] => -129 [4] => -128 [5] => -127 [6] => -126 )
Output for 5.5.30
2015-11-13 00:00 2016-04-01 11:12:08 143Array ( [0] => -143 [1] => -142 [2] => -141 [3] => -140 [4] => -139 [5] => -138 [6] => -137 )
Output for 5.5.29
2015-11-13 00:00 2016-04-17 05:57:07 159Array ( [0] => -159 [1] => -158 [2] => -157 [3] => -156 [4] => -155 [5] => -154 [6] => -153 )
Output for 5.5.28
2015-11-13 00:00 2016-04-21 09:17:25 163Array ( [0] => -163 [1] => -162 [2] => -161 [3] => -160 [4] => -159 [5] => -158 [6] => -157 )
Output for 5.5.27
2015-11-13 00:00 2016-04-22 11:03:36 164Array ( [0] => -164 [1] => -163 [2] => -162 [3] => -161 [4] => -160 [5] => -159 [6] => -158 )
Output for 5.5.26
2015-11-13 00:00 2016-04-26 17:11:44 168Array ( [0] => -168 [1] => -167 [2] => -166 [3] => -165 [4] => -164 [5] => -163 [6] => -162 )
Output for 5.5.25
2015-11-13 00:00 2016-04-29 00:07:20 171Array ( [0] => -171 [1] => -170 [2] => -169 [3] => -168 [4] => -167 [5] => -166 [6] => -165 )
Output for 5.5.24
2015-11-13 00:00 2016-05-24 06:36:15 196Array ( [0] => -196 [1] => -195 [2] => -194 [3] => -193 [4] => -192 [5] => -191 [6] => -190 )
Output for 5.4.44 - 5.4.45
2015-11-13 00:00 2015-11-10 15:50:42 0Array ( [0] => -3 [1] => -2 [2] => -1 [3] => 0 [4] => 1 [5] => 2 [6] => 3 )
Output for 5.4.43
2015-11-13 00:00 2015-11-10 15:50:43 0Array ( [0] => -3 [1] => -2 [2] => -1 [3] => 0 [4] => 1 [5] => 2 [6] => 3 )
Output for 5.4.40 - 5.4.42
2015-11-13 00:00 2015-11-10 15:50:44 0Array ( [0] => -3 [1] => -2 [2] => -1 [3] => 0 [4] => 1 [5] => 2 [6] => 3 )
Output for 5.4.35 - 5.4.39
2015-11-13 00:00 2015-11-10 15:50:45 0Array ( [0] => -3 [1] => -2 [2] => -1 [3] => 0 [4] => 1 [5] => 2 [6] => 3 )
Output for 5.4.31 - 5.4.34
2015-11-13 00:00 2015-11-10 15:50:46 0Array ( [0] => -3 [1] => -2 [2] => -1 [3] => 0 [4] => 1 [5] => 2 [6] => 3 )
Output for 5.4.25 - 5.4.30
2015-11-13 00:00 2015-11-10 15:50:47 0Array ( [0] => -3 [1] => -2 [2] => -1 [3] => 0 [4] => 1 [5] => 2 [6] => 3 )
Output for 5.4.19 - 5.4.24
2015-11-13 00:00 2015-11-10 15:50:48 0Array ( [0] => -3 [1] => -2 [2] => -1 [3] => 0 [4] => 1 [5] => 2 [6] => 3 )
Output for 5.4.15 - 5.4.18
2015-11-13 00:00 2015-11-10 15:50:49 0Array ( [0] => -3 [1] => -2 [2] => -1 [3] => 0 [4] => 1 [5] => 2 [6] => 3 )
Output for 5.4.11 - 5.4.14
2015-11-13 00:00 2015-11-10 15:50:50 0Array ( [0] => -3 [1] => -2 [2] => -1 [3] => 0 [4] => 1 [5] => 2 [6] => 3 )
Output for 5.4.9 - 5.4.10
2015-11-13 00:00 2015-11-10 15:50:51 0Array ( [0] => -3 [1] => -2 [2] => -1 [3] => 0 [4] => 1 [5] => 2 [6] => 3 )
Output for 5.3.19 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/7kX4G on line 3
Process exited with code 255.