php - creating dates+times every 15 minutes does not work -
my php code below supposed create list of following dates + times.
// code goes here $maxdays = 1; for($daynumber=0;$daynumber<$maxdays;$daynumber++){ $currentdayval = "+".(string)($daynumber-$maxdays)." days"; $minutes=0; for($quarter=0;$quarter<24*4;$quarter++){ $minutes += $quarter*15; $currentminutesval = $minutes." minutes"; $date_sql = date("y-m-d h:i:s",strtotime($currentdayval." + ".$currentminutesval)); //current date echo $date_sql. "\n"; }//for $quarter }//for $daynr
but output below shows not every date/time follows 15 minutes after previous date/time. not sure code goes wrong(?)
2014-06-26 12:44:15 2014-06-26 12:59:15 2014-06-26 13:29:15 2014-06-26 14:14:15 2014-06-26 15:14:15 2014-06-26 16:29:15 2014-06-26 17:59:15 2014-06-26 19:44:15 2014-06-26 21:44:15 2014-06-26 23:59:15 2014-06-27 02:29:15 2014-06-27 05:14:15 2014-06-27 08:14:15 2014-06-27 11:29:15
for code work, need $minutes
0, 15, 30, 45...
but because you're incrementing, $minutes
set 0, 15... 45 (15+30), 90 (15+30+45), 150 (15+30+45+60)...
try $minutes = $quarter * 15;
instead of +=
Comments
Post a Comment