Canman2005 Posted September 16, 2007 Share Posted September 16, 2007 Hi all Im wondering if anyone can help me, basically im trying to print a list of every Friday since a date defined. Let me try and explain. I want to define a date such as 2007-07-06 (which is a Friday) and then let php print each Friday since that date until today. For example, if the date defined was 2007-07-06 then it would print 2007-07-06 2007-07-13 2007-07-20 2007-07-27 2007-08-03 2007-08-10 2007-08-17 2007-08-24 2007-08-31 2007-09-07 2007-09-14 But I want to also be able to format the date it outputs, so it might look like Friday 06 July 2007 Friday 13 July 2007 Friday 20 July 2007 and so on Can anyone help me? Thanks in advance Ed Quote Link to comment https://forums.phpfreaks.com/topic/69606-printing-every-week/ Share on other sites More sharing options...
cooldude832 Posted September 16, 2007 Share Posted September 16, 2007 You can do some sort of function usign the start day and then basically say $day = mktime(nextfriday, $dateentered); then say while($day < $today){ $day = mktime(nextfriday, $day); //Format $day to your need and print } There is a time flag called Next Day of the week, I had a list of em somewhere but this is the just Quote Link to comment https://forums.phpfreaks.com/topic/69606-printing-every-week/#findComment-349786 Share on other sites More sharing options...
btherl Posted September 17, 2007 Share Posted September 17, 2007 Formatting is done with the date() function. You can use strtotime() and add 1 week to get the next friday. For example, date('Y-m-d', strtotime('2007-09-01 +1 week')). I'm not sure how that handles DST changes, but it's probably ok.. To find the first friday, you can use strtotime()'s other features like 'next Friday' Quote Link to comment https://forums.phpfreaks.com/topic/69606-printing-every-week/#findComment-349845 Share on other sites More sharing options...
Canman2005 Posted September 17, 2007 Author Share Posted September 17, 2007 Hi I tried <?php $today = 2007-09-21; $day = mktime(nextfriday, $dateentered); while($day < $today){ $day = mktime(nextfriday, $day); print $day; } ?> but that didnt seem to work, can anyone help me out? Thanks Ed Quote Link to comment https://forums.phpfreaks.com/topic/69606-printing-every-week/#findComment-350204 Share on other sites More sharing options...
Barand Posted September 17, 2007 Share Posted September 17, 2007 <?php $date = '2007-06-18' ; $friday = strtotime("next friday $date"); while ($friday <= mktime(0,0,0)) { echo date('l d F Y', $friday), '<br/>'; $friday = strtotime('+7 days', $friday); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/69606-printing-every-week/#findComment-350207 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.