canabatz Posted February 26, 2016 Share Posted February 26, 2016 (edited) hi all i have an array that hold times as follow(i define the date): 2016-02-24 16:552016-02-24 17:552016-02-24 19:552016-02-24 23:552016-02-24 01:34 -<----here is my problem , i want the date to change if it's after midnight. it shuold be like that automaticly:2016-02-25 01:34 somthing like that: $day="2016-02-26"; if(strtotime(01:34) > strtotime("23:59")) { $day = date('Y-m-d',strtotime($day."+1 days")); } else { //KEEP CURRENT DATE } the time im geting from a web site with file_get_contents and there the date do not change if after midnight so i got to do it my self any help ? thanks Edited February 26, 2016 by canabatz Quote Link to comment Share on other sites More sharing options...
requinix Posted February 26, 2016 Share Posted February 26, 2016 What are you doing to advance the time? If you did that part properly then the date would advance when it should automatically. Quote Link to comment Share on other sites More sharing options...
canabatz Posted February 26, 2016 Author Share Posted February 26, 2016 im getting the time from other server and the date dosent change there it's showing same date but times after midnight also. what i need is programaticly change the date myself with a script. thanks Quote Link to comment Share on other sites More sharing options...
Solution Barand Posted February 26, 2016 Solution Share Posted February 26, 2016 here's one way $arr = [ '2016-02-24 16:55', '2016-02-24 17:55', '2016-02-24 19:55', '2016-02-24 23:55', '2016-02-24 00:35', '2016-02-24 01:34' ]; for ($i=1, $j=0, $k=count($arr); $i<$k; $i++, $j++) { $dj = new DateTime($arr[$j]); $di = new DateTime($arr[$i]); if ($di < $dj) { $arr[$i] = $di->modify('+1 days')->format('Y-m-d H:i'); } } echo '<pre>',print_r($arr, true),'</pre>'; /* RESULT ************* Array ( [0] => 2016-02-24 16:55 [1] => 2016-02-24 17:55 [2] => 2016-02-24 19:55 [3] => 2016-02-24 23:55 [4] => 2016-02-25 00:35 [5] => 2016-02-25 01:34 ) ****************************/ Quote Link to comment Share on other sites More sharing options...
canabatz Posted February 26, 2016 Author Share Posted February 26, 2016 Thanks a lot , exactly what i needed Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.