davids701124 Posted October 20, 2009 Share Posted October 20, 2009 I have generate days between 2 dates, the code is following: $day = 24 * 60 * 60; $sTime = strtotime('2009-10-20'); //it doesn't work putting $row["user_registered"] $eTime = strtotime('2010-08-10'); //it doesn't work putting $row["user_registered"] $numDays = (($eTime - $sTime) / $day + 1); $numWeeks = $numDays / 7; print $numWeeks; and now I wanna create a table; the row is week number, ex: week1, week2,...;the column is day, from Mon to Sun. and each field will contain exactly date, ex: 2009-10-20.... So I'm wondering how can I know which day is belong which week? Quote Link to comment Share on other sites More sharing options...
kickstart Posted October 20, 2009 Share Posted October 20, 2009 Hi I presume you want a list of table of them. Something like this will do it, but not that efficient (the strfrtime to determine the day of the week could be coded round if you wanted):- $DayCnt = 0; for($aCnt = $sTime ; $aCnt <= $eTime ; $aCnt += 86400) { $DayOfWeek = strftime('%w',$aCnt ); if ($DayOfWeek != $DayCnt) { echo '<tr>'; for($DayCnt = 0 ; $DayCnt < $DayOfWeek ; $DayCnt++) { echo '<td> </td>'; } } echo '<td>'.strftime('%d/%b/%Y',$aCnt ).'</td>'; $DayCnt++; if ($DayCnt >= 7) { $DayCnt = 0; echo '</tr>'; } } for($aCnt = $DayCnt ; $DayCnt < 7 ; $aCnt++) { echo '<td> </td>'; } echo '</tr>'; This is days from Sun to Sat. All the best Keith Quote Link to comment Share on other sites More sharing options...
davids701124 Posted October 20, 2009 Author Share Posted October 20, 2009 After tried it, it prints out all date together without table. However, I think it is closed, I'm gonna try to tweak it for fitting what I exactly need. I'm wondering wht is the meaning of $DayCnt? Thank you very much. Quote Link to comment Share on other sites More sharing options...
kickstart Posted October 20, 2009 Share Posted October 20, 2009 Hi You did out the table tags around it? $DayCnt is just used as a count of the current day of the week being processed, so varies from 0 to 6. All the best Keith Quote Link to comment Share on other sites More sharing options...
davids701124 Posted October 20, 2009 Author Share Posted October 20, 2009 not really, my first try didn't take anything away. I'm wondering why the table tag doesn't work either. Anyway, thanks for helping. I'm gonna try it more. 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.