OldWest Posted December 2, 2010 Share Posted December 2, 2010 I am doing some study on using time() and date() and i just wrote this simple for loop to add one day to each iteration with +$i and its echoing the unix timestamp as opposed to the correctly formated date as it should be based on my code. Anyone have any idea why this is not working as expected? for($i=0; $i < 50; $i++) { echo $time = time()+$i . "<br />"; // add a day on each iteration echo date('y-m-d', $time) . "<br />"; // should echo 10-12-02, 10-12-03, 10-12-04, etc.. } what am i doing wrong here? arrgggg! maybe its too late for this s$%^#! Quote Link to comment Share on other sites More sharing options...
OldWest Posted December 2, 2010 Author Share Posted December 2, 2010 SOLVED: for($i=0; $i < 50; $i++) { echo date('D, F jS, Y', strtotime("+$i days")) . "<br />"; } Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted December 2, 2010 Share Posted December 2, 2010 If you want to do this using your original concept, you need to increment $i by 86400, since the time function returns seconds and there are 86400 seconds in a day (except when DST starts/ends). <?php $end = 50 * 86400; for ($i=0;$i< $end; $i += 86400) { $time = time() + $i; echo date('y-m-d', $time) . "<br />"; ?> Ken 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.