3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $days = []; $searchData = ['dat' => '2015-11-12']; $offset = 3; $now = date_create('today'); $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'); echo PHP_EOL . date_create($searchData['dat'])->diff($now)->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);
based on V40N2
Output for 5.4.9 - 5.4.45, 5.6.28, 7.0.20 - 7.2.0
2015-11-09 00:00 2015-11-10 00:00 2Array ( [0] => -2 [1] => -1 [2] => 0 [3] => 1 [4] => 2 [5] => 3 [6] => 4 )
Output for 7.0.6
2015-11-09 00:00 2016-05-03 00:00 173Array ( [0] => -173 [1] => -172 [2] => -171 [3] => -170 [4] => -169 [5] => -168 [6] => -167 )
Output for 7.0.5
2015-11-09 00:00 2016-04-03 00:00 143Array ( [0] => -143 [1] => -142 [2] => -141 [3] => -140 [4] => -139 [5] => -138 [6] => -137 )
Output for 7.0.4
2015-11-09 00:00 2016-03-10 00:00 119Array ( [0] => -119 [1] => -118 [2] => -117 [3] => -116 [4] => -115 [5] => -114 [6] => -113 )
Output for 7.0.3
2015-11-09 00:00 2016-03-18 00:00 127Array ( [0] => -127 [1] => -126 [2] => -125 [3] => -124 [4] => -123 [5] => -122 [6] => -121 )
Output for 7.0.2
2015-11-09 00:00 2016-03-23 00:00 132Array ( [0] => -132 [1] => -131 [2] => -130 [3] => -129 [4] => -128 [5] => -127 [6] => -126 )
Output for 7.0.1
2015-11-09 00:00 2016-03-24 00:00 133Array ( [0] => -133 [1] => -132 [2] => -131 [3] => -130 [4] => -129 [5] => -128 [6] => -127 )
Output for 7.0.0
2015-11-09 00:00 2016-03-27 00:00 136Array ( [0] => -136 [1] => -135 [2] => -134 [3] => -133 [4] => -132 [5] => -131 [6] => -130 )
Output for 5.6.21
2015-11-09 00:00 2016-05-02 00:00 172Array ( [0] => -172 [1] => -171 [2] => -170 [3] => -169 [4] => -168 [5] => -167 [6] => -166 )
Output for 5.6.20
2015-11-09 00:00 2016-04-10 00:00 150Array ( [0] => -150 [1] => -149 [2] => -148 [3] => -147 [4] => -146 [5] => -145 [6] => -144 )
Output for 5.6.19
2015-11-09 00:00 2016-03-08 00:00 117Array ( [0] => -117 [1] => -116 [2] => -115 [3] => -114 [4] => -113 [5] => -112 [6] => -111 )
Output for 5.6.18
2015-11-09 00:00 2016-03-15 00:00 124Array ( [0] => -124 [1] => -123 [2] => -122 [3] => -121 [4] => -120 [5] => -119 [6] => -118 )
Output for 5.6.17
2015-11-09 00:00 2016-03-19 00:00 128Array ( [0] => -128 [1] => -127 [2] => -126 [3] => -125 [4] => -124 [5] => -123 [6] => -122 )
Output for 5.6.16
2015-11-09 00:00 2016-03-28 00:00 137Array ( [0] => -137 [1] => -136 [2] => -135 [3] => -134 [4] => -133 [5] => -132 [6] => -131 )
Output for 5.6.15
2015-11-09 00:00 2016-03-29 00:00 138Array ( [0] => -138 [1] => -137 [2] => -136 [3] => -135 [4] => -134 [5] => -133 [6] => -132 )
Output for 5.6.14
2015-11-09 00:00 2016-04-02 00:00 142Array ( [0] => -142 [1] => -141 [2] => -140 [3] => -139 [4] => -138 [5] => -137 [6] => -136 )
Output for 5.6.13
2015-11-09 00:00 2016-04-15 00:00 155Array ( [0] => -155 [1] => -154 [2] => -153 [3] => -152 [4] => -151 [5] => -150 [6] => -149 )
Output for 5.6.12
2015-11-09 00:00 2016-04-20 00:00 160Array ( [0] => -160 [1] => -159 [2] => -158 [3] => -157 [4] => -156 [5] => -155 [6] => -154 )
Output for 5.6.11
2015-11-09 00:00 2016-04-24 00:00 164Array ( [0] => -164 [1] => -163 [2] => -162 [3] => -161 [4] => -160 [5] => -159 [6] => -158 )
Output for 5.6.10
2015-11-09 00:00 2016-04-25 00:00 165Array ( [0] => -165 [1] => -164 [2] => -163 [3] => -162 [4] => -161 [5] => -160 [6] => -159 )
Output for 5.6.9
2015-11-09 00:00 2016-04-27 00:00 167Array ( [0] => -167 [1] => -166 [2] => -165 [3] => -164 [4] => -163 [5] => -162 [6] => -161 )
Output for 5.6.8
2015-11-09 00:00 2016-04-30 00:00 170Array ( [0] => -170 [1] => -169 [2] => -168 [3] => -167 [4] => -166 [5] => -165 [6] => -164 )
Output for 5.5.35
2015-11-09 00:00 2016-05-22 00:00 192Array ( [0] => -192 [1] => -191 [2] => -190 [3] => -189 [4] => -188 [5] => -187 [6] => -186 )
Output for 5.5.34
2015-11-09 00:00 2016-04-11 00:00 151Array ( [0] => -151 [1] => -150 [2] => -149 [3] => -148 [4] => -147 [5] => -146 [6] => -145 )
Output for 5.5.33
2015-11-09 00:00 2016-03-09 00:00 118Array ( [0] => -118 [1] => -117 [2] => -116 [3] => -115 [4] => -114 [5] => -113 [6] => -112 )
Output for 5.5.32
2015-11-09 00:00 2016-03-17 00:00 126Array ( [0] => -126 [1] => -125 [2] => -124 [3] => -123 [4] => -122 [5] => -121 [6] => -120 )
Output for 5.5.31
2015-11-09 00:00 2016-03-21 00:00 130Array ( [0] => -130 [1] => -129 [2] => -128 [3] => -127 [4] => -126 [5] => -125 [6] => -124 )
Output for 5.5.30
2015-11-09 00:00 2016-04-01 00:00 141Array ( [0] => -141 [1] => -140 [2] => -139 [3] => -138 [4] => -137 [5] => -136 [6] => -135 )
Output for 5.5.29
2015-11-09 00:00 2016-04-17 00:00 157Array ( [0] => -157 [1] => -156 [2] => -155 [3] => -154 [4] => -153 [5] => -152 [6] => -151 )
Output for 5.5.28
2015-11-09 00:00 2016-04-21 00:00 161Array ( [0] => -161 [1] => -160 [2] => -159 [3] => -158 [4] => -157 [5] => -156 [6] => -155 )
Output for 5.5.27
2015-11-09 00:00 2016-04-22 00:00 162Array ( [0] => -162 [1] => -161 [2] => -160 [3] => -159 [4] => -158 [5] => -157 [6] => -156 )
Output for 5.5.26
2015-11-09 00:00 2016-04-26 00:00 166Array ( [0] => -166 [1] => -165 [2] => -164 [3] => -163 [4] => -162 [5] => -161 [6] => -160 )
Output for 5.5.25
2015-11-09 00:00 2016-04-29 00:00 169Array ( [0] => -169 [1] => -168 [2] => -167 [3] => -166 [4] => -165 [5] => -164 [6] => -163 )
Output for 5.5.24
2015-11-09 00:00 2016-05-24 00:00 194Array ( [0] => -194 [1] => -193 [2] => -192 [3] => -191 [4] => -190 [5] => -189 [6] => -188 )
Output for 5.3.19 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/COUbl on line 3
Process exited with code 255.