3v4l.org

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