leachus2002 Posted February 8, 2011 Share Posted February 8, 2011 Hi There, I am trying to create a table, and accross the top I would like the Week Commencing Dates of the last 5 weeks. So for example: <table> <tr><td>07/02</td><td>31/01</td><td>24/01</td><td>17/01</td><td>10/01</td></tr> </table> Can anyone help? Cheers Matt Link to comment https://forums.phpfreaks.com/topic/227056-echo-wc-dates/ Share on other sites More sharing options...
kenrbnsn Posted February 8, 2011 Share Posted February 8, 2011 What have you tried? Ken Link to comment https://forums.phpfreaks.com/topic/227056-echo-wc-dates/#findComment-1171488 Share on other sites More sharing options...
leachus2002 Posted February 9, 2011 Author Share Posted February 9, 2011 Hi Ken, I am not sure where to start - I am happy with dates and all, but not sure how to get just Monday dates etc etc. Cheers Matt Link to comment https://forums.phpfreaks.com/topic/227056-echo-wc-dates/#findComment-1171726 Share on other sites More sharing options...
kenrbnsn Posted February 9, 2011 Share Posted February 9, 2011 When playing with dates, I like to use strtotime in combination with date. Other people like to use other functions. Try: <?php $dates = array(); $start = (date('l') == 'Monday')?time():strtotime('last monday'); $add7days = 86400 * 7; for ($i = 0;$i < 5;++$i) { $dates[$i] = date('d/m',$start + ($i * $add7days)); } echo '<table><tr><td>' . implode('</td><td>',$dates) . '</td></tr></table>'; ?> Ken Link to comment https://forums.phpfreaks.com/topic/227056-echo-wc-dates/#findComment-1171861 Share on other sites More sharing options...
leachus2002 Posted February 10, 2011 Author Share Posted February 10, 2011 Hi Ken, That's great, just what I need - however it is giving me the next 5 weeks, rather than the last 5 - is that easy to change? Thanks Matt Link to comment https://forums.phpfreaks.com/topic/227056-echo-wc-dates/#findComment-1172210 Share on other sites More sharing options...
zenlord Posted February 10, 2011 Share Posted February 10, 2011 I guess you really should read up on for-loops... Try changing ++ in -- Or: start at -5 and then ++ until you reach 0... Link to comment https://forums.phpfreaks.com/topic/227056-echo-wc-dates/#findComment-1172215 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.