DazlerD Posted March 23, 2007 Share Posted March 23, 2007 Hi I wrote a website a few months ago thats shows user calendars. It has been working great until now. The calendar shows one week at a time and the user can press < and > hrefs to go the previous and next weeks. My problem occurs when the end of the week is the 24/03/2007. The date it uses for the start of next week is only 6 days after the start of the week from today. The code says today=24/03/2007, startofweek=18/03/2007, endofweek=24/03/2007 and startofnextweek=24/03/2007. When it processes the form with the startofnextweek it works out this is not a sunday (weeks go from sunday to saturday) so shows the same week beginning 18/03/2007. Heres some debug statements starting from the start of march. Passed Date: 04/03/2007 Today Date: 01/01/1970 Begin Date: 04/03/2007 Today Date from todaydate: 23/03/2007 Start of the week:04/03/2007 End of the week:10/03/2007 Start of next week:11/03/2007 Week Number: 5 First Editable Date:24/03/2007 Passed Date: 11/03/2007 Today Date: 01/01/1970 Begin Date: 11/03/2007 Today Date from todaydate: 23/03/2007 Start of the week:11/03/2007 End of the week:17/03/2007 Start of next week:18/03/2007 Week Number: 6 First Editable Date:24/03/2007 Passed Date: 18/03/2007 Today Date: 01/01/1970 Begin Date: 18/03/2007 Today Date from todaydate: 23/03/2007 Start of the week:18/03/2007 End of the week:24/03/2007 Start of next week:24/03/2007 Week Number: 7 First Editable Date:24/03/2007 Passed Date: 24/03/2007 Today Date: 01/01/1970 Begin Date: 24/03/2007 Today Date from todaydate: 23/03/2007 Start of the week:18/03/2007 End of the week:24/03/2007 Start of next week:24/03/2007 Week Number: 7 First Editable Date:24/03/2007 HERES THE CODE //$today displays todays date (dd/mm/yyyy) $today = date('d/m/Y'); //$todaydate sets to to days $todaydate = mktime(0,0,0,date("n"),date("j"),date("Y")); //$Begins sets to todays $Begin = mktime(0,0,0,date('n', $todaydate),date('j', $todaydate),date('Y', $todaydate)); // Start of week $StartOfWeek = mktime(0,0,0,date("n", $Begin),(date("j", $Begin)-date("w",$Begin) + $dateCompensator),date("Y")); // last day of the week Start add 6 days $EndOfWeek = mktime(23,59,59,date("n", date($StartOfWeek)),(date("j", date($StartOfWeek))+6),date("Y", date($StartOfWeek))); // start of next week Start add 7 days $StartNextWeek = mktime(0,0,0,date("n", date($StartOfWeek)),(date("j", date($StartOfWeek))+7),date("Y", date($StartOfWeek))); // start of last week Start minus 7 days $StartLastWeek = mktime(0,0,0,date("n", date($StartOfWeek)),(date("j", date($StartOfWeek))-7),date("Y", date($StartOfWeek))); // this is the first possible day you can edit, tomorrow $FirstEditDate = mktime(0,0,0,date("n"), date("j") + 1,date("Y")); The startofweek always gets set correctly. The startofnext week only fails this week!! Anyone any ideas why the startofnextweek gets worked out incorrectly? Im really confused. Ive tried adding 8 days from the startofweek and subtracting one, Ive tried messing with times, Ive tried adding 1 day onto the endofweek. I still get the same result. Thanks for any suggestions! Darren Quote Link to comment Share on other sites More sharing options...
mjlogan Posted March 23, 2007 Share Posted March 23, 2007 That is a lot of text ^^, but I have just one suggestion, never store dates as mm-dd-yy, mm-dd-yyyy, dd/mm/yy, ddmmyy hhss and so on and so on, save them as timestamps, it is much much easier to work with timestamps, I have just written a web timesheet system and its timestamps all the way through as it is much much easier to work with. echo strtotime("next sunday", time()); Quote Link to comment Share on other sites More sharing options...
DazlerD Posted March 26, 2007 Author Share Posted March 26, 2007 Hi I believe I am using timestamps. The debug was shown after being converted to date. Passed Date: 01/01/1970 Today Date: 01/01/1970 Begin Date: 26/03/2007 Today Date from todaydate: 26/03/2007 Start of the week:24/03/2007 End of the week:30/03/2007 Start of next week:31/03/2007 Week Number: 8 First Editable Date:27/03/2007 Passed Date: 0 Today Date: 26/03/2007 Begin Date: 1174863600 Today Date from todaydate: 1174863600 Start of the week:1174777200 End of the week:1175295599 Start of next week:1175299200 Week Number: 8 First Editable Date:1174950000 When first loaded the page shows the correct week, week8. However it wont go forward to week 9, and, if you go backwards it goes to week 6 and then on going forward it goes to 7 but wont go on to this week 8. Its weird. If any has any ideas please let me know !! Thanks Quote Link to comment Share on other sites More sharing options...
mjlogan Posted March 26, 2007 Share Posted March 26, 2007 //$today displays todays date (dd/mm/yyyy) $today = time(); echo $today."\n"; echo "Today: ".date('d/m/Y', $today)."\n\n"; // Start of week $StartOfWeek = strtotime("last sunday", $today); echo $StartOfWeek."\n"; echo "Week Start: ".date('d/m/Y', $StartOfWeek)."\n\n"; // last day of the week Start add 6 days $EndOfWeek = strtotime("+6 day", $today); echo $EndOfWeek."\n"; echo "Six Days Time: ".date('d/m/Y', $EndOfWeek)."\n\n"; // start of next week Start add 7 days $StartNextWeek = strtotime("+7 day", $today); echo $StartNextWeek."\n"; echo "Seven Days Time: ".date('d/m/Y', $StartNextWeek)."\n\n"; // start of last week Start minus 7 days $StartLastWeek = strtotime("-7 day", $today); echo $StartLastWeek."\n"; echo "Seven Days Ago: ".date('d/m/Y', $StartLastWeek)."\n\n"; // this is the first possible day you can edit, tomorrow $FirstEditDate = $today+86400; echo $FirstEditDate."\n"; echo "Tomorrow: ".date('d/m/Y', $FirstEditDate)."\n\n"; any help? I don't really understand what days you are after. Have you tried using timestamps and strtotime? Quote Link to comment Share on other sites More sharing options...
btherl Posted March 26, 2007 Share Posted March 26, 2007 This looks like a DST issue. DST typically starts on 25 March. But your code looks ok to me. mktime() is supposed to handle DST changes. Maybe try another way of calculating? Quote Link to comment Share on other sites More sharing options...
mjlogan Posted March 26, 2007 Share Posted March 26, 2007 <?php $now = strtotime("-70 day", time()); while($now < time()+200000){ echo "####################################\n"; echo " NEW WEEK\n"; echo "####################################\n\n"; //$today displays todays date (dd/mm/yyyy) $today = $now; echo $today."\n"; echo "Today: ".date('d/m/Y', $today)."\n\n"; // Start of week $StartOfWeek = strtotime("last sunday", $today); echo $StartOfWeek."\n"; echo "Week Start: ".date('d/m/Y', $StartOfWeek)."\n\n"; // last day of the week Start add 6 days $EndOfWeek = strtotime("+6 day", $today); echo $EndOfWeek."\n"; echo "Six Days Time: ".date('d/m/Y', $EndOfWeek)."\n\n"; // start of next week Start add 7 days $StartNextWeek = strtotime("+7 day", $today); echo $StartNextWeek."\n"; echo "Seven Days Time: ".date('d/m/Y', $StartNextWeek)."\n\n"; // start of last week Start minus 7 days $StartLastWeek = strtotime("-7 day", $today); echo $StartLastWeek."\n"; echo "Seven Days Ago: ".date('d/m/Y', $StartLastWeek)."\n\n"; // this is the first possible day you can edit, tomorrow $FirstEditDate = $today+86400; echo $FirstEditDate."\n"; echo "Tomorrow: ".date('d/m/Y', $FirstEditDate)."\n\n"; $now = strtotime("+1 week", $now); } ?> Quote Link to comment Share on other sites More sharing options...
DazlerD Posted March 26, 2007 Author Share Posted March 26, 2007 Thanks for the help/advice guys btherl: Im running php 4.3 would a newer version of PSP fix the DST problem? mjlogan when I run your code I get (I had to change 200000 to 1000000 to get it into next week). #################################### NEW WEEK #################################### 1168860475 Today: 15/01/2007 1168732800 Week Start: 14/01/2007 1169378875 Six Days Time: 21/01/2007 1169465275 Seven Days Time: 22/01/2007 1168255675 Seven Days Ago: 08/01/2007 1168946875 Tomorrow: 16/01/2007 #################################### NEW WEEK #################################### 1169465275 Today: 22/01/2007 1169337600 Week Start: 21/01/2007 1169983675 Six Days Time: 28/01/2007 1170070075 Seven Days Time: 29/01/2007 1168860475 Seven Days Ago: 15/01/2007 1169551675 Tomorrow: 23/01/2007 #################################### NEW WEEK #################################### 1170070075 Today: 29/01/2007 1169942400 Week Start: 28/01/2007 1170588475 Six Days Time: 04/02/2007 1170674875 Seven Days Time: 05/02/2007 1169465275 Seven Days Ago: 22/01/2007 1170156475 Tomorrow: 30/01/2007 #################################### NEW WEEK #################################### 1170674875 Today: 05/02/2007 1170547200 Week Start: 04/02/2007 1171193275 Six Days Time: 11/02/2007 1171279675 Seven Days Time: 12/02/2007 1170070075 Seven Days Ago: 29/01/2007 1170761275 Tomorrow: 06/02/2007 #################################### NEW WEEK #################################### 1171279675 Today: 12/02/2007 1171152000 Week Start: 11/02/2007 1171798075 Six Days Time: 18/02/2007 1171884475 Seven Days Time: 19/02/2007 1170674875 Seven Days Ago: 05/02/2007 1171366075 Tomorrow: 13/02/2007 #################################### NEW WEEK #################################### 1171884475 Today: 19/02/2007 1171756800 Week Start: 18/02/2007 1172402875 Six Days Time: 25/02/2007 1172489275 Seven Days Time: 26/02/2007 1171279675 Seven Days Ago: 12/02/2007 1171970875 Tomorrow: 20/02/2007 #################################### NEW WEEK #################################### 1172489275 Today: 26/02/2007 1172361600 Week Start: 25/02/2007 1173007675 Six Days Time: 04/03/2007 1173094075 Seven Days Time: 05/03/2007 1171884475 Seven Days Ago: 19/02/2007 1172575675 Tomorrow: 27/02/2007 #################################### NEW WEEK #################################### 1173094075 Today: 05/03/2007 1172966400 Week Start: 04/03/2007 1173612475 Six Days Time: 11/03/2007 1173698875 Seven Days Time: 12/03/2007 1172489275 Seven Days Ago: 26/02/2007 1173180475 Tomorrow: 06/03/2007 #################################### NEW WEEK #################################### 1173698875 Today: 12/03/2007 1173571200 Week Start: 11/03/2007 1174217275 Six Days Time: 18/03/2007 1174303675 Seven Days Time: 19/03/2007 1173094075 Seven Days Ago: 05/03/2007 1173785275 Tomorrow: 13/03/2007 #################################### NEW WEEK #################################### 1174303675 Today: 19/03/2007 1174176000 Week Start: 18/03/2007 1174818475 Six Days Time: 25/03/2007 1174904875 Seven Days Time: 26/03/2007 1173698875 Seven Days Ago: 12/03/2007 1174390075 Tomorrow: 20/03/2007 #################################### NEW WEEK #################################### 1174904875 Today: 26/03/2007 1174777200 Week Start: 24/03/2007 1175423275 Six Days Time: 01/04/2007 1175509675 Seven Days Time: 02/04/2007 1174303675 Seven Days Ago: 19/03/2007 1174991275 Tomorrow: 27/03/2007 #################################### NEW WEEK #################################### 1175509675 Today: 02/04/2007 1175382000 Week Start: 01/04/2007 1176028075 Six Days Time: 08/04/2007 1176114475 Seven Days Time: 09/04/2007 1174904875 Seven Days Ago: 26/03/2007 1175596075 Tomorrow: 03/04/2007 ********************************************* Which looks good. The calendar on the screen runs frm sunday on the left to Saturday on the right. There are two hrefs one to go backwards and one to go forwards a week at a time. The href pass the start of the week back into the same form. This then works out the start of that week, the start of the previous week and next weeks etc. Im going to try now...... Quote Link to comment Share on other sites More sharing options...
DazlerD Posted March 26, 2007 Author Share Posted March 26, 2007 IVE JUST NOTICED IN THE ABOVE POST IT STILL COMES OUT WRONG: (This was added after this post was written) #################################### NEW WEEK #################################### 1174904875 Today: 26/03/2007 1174777200 Week Start: 24/03/2007 1175423275 Six Days Time: 01/04/2007 1175509675 Seven Days Time: 02/04/2007 1174303675 Seven Days Ago: 19/03/2007 1174991275 Tomorrow: 27/03/2007 **************************************** Heres my code now: //$todaydate sets to to days $todaydate = time(); // $Begin set to the $PassedStartDate if ($PassedStartDate) { $Begin = $PassedStartDate; } else { $Begin = $todaydate; } // sunday $dateCompensator = 0; // 0 if start day is Sunday on my system $StartOfWeek = strtotime("last sunday", $Begin); // last day of the week Start add 6 days $EndOfWeek = strtotime("+6 day", $StartOfWeek); // start of next week $StartNextWeek = strtotime("+7 day", $StartOfWeek); // start of next week $StartLastWeek = strtotime("-7 day", $StartOfWeek); // this is the first possible day you can edit, tomorrow FirstEditDate = strtotime("+1 day", $todaydate); THis returns (for today): Passed Date: 01/01/1970 Begin Date: 26/03/2007 Today Date from todaydate: 26/03/2007 Start of the week:24/03/2007 End of the week:30/03/2007 Start of last week:17/03/2007 Start of next week:31/03/2007 Week Number: 8 First Editable Date:27/03/2007 Seems to me that its the calculation of the start of the current week is wrong. It should find the previous Sunday or if a Sunday use the current day. Its returning Saturday 24th March 2007. Even if I use: $StartOfWeek = mktime(0,0,0,date("n", $Begin),(date("j", $Begin)-date("w",$Begin) + $dateCompensator),date("Y")); it still returnS the 24th. Damn this is annoying me now !! It must be the DST going wrong. Quote Link to comment Share on other sites More sharing options...
mjlogan Posted March 26, 2007 Share Posted March 26, 2007 <?php $dst = date('I', $date); if($dst=='1'){ $now = strtotime("-70 day", time()-3600); } else { $now = strtotime("-70 day", time()); } while($now < time()+800000){ echo "####################################\n"; echo " NEW WEEK\n"; echo "####################################\n\n"; //$today displays todays date (dd/mm/yyyy) $today = $now; echo $today."\n"; echo "Today: ".date('d/m/Y', $today)."\n\n"; // Start of week $StartOfWeek = strtotime("last sunday", $today); echo $StartOfWeek."\n"; echo "Week Start: ".date('d/m/Y', $StartOfWeek)."\n\n"; // last day of the week Start add 6 days $EndOfWeek = strtotime("+6 day", $today); echo $EndOfWeek."\n"; echo "Six Days Time: ".date('d/m/Y', $EndOfWeek)."\n\n"; // start of next week Start add 7 days $StartNextWeek = strtotime("+7 day", $today); echo $StartNextWeek."\n"; echo "Seven Days Time: ".date('d/m/Y', $StartNextWeek)."\n\n"; // start of last week Start minus 7 days $StartLastWeek = strtotime("-7 day", $today); echo $StartLastWeek."\n"; echo "Seven Days Ago: ".date('d/m/Y', $StartLastWeek)."\n\n"; // this is the first possible day you can edit, tomorrow $FirstEditDate = $today+86400; echo $FirstEditDate."\n"; echo "Tomorrow: ".date('d/m/Y', $FirstEditDate)."\n\n"; $now = strtotime("+1 week", $now); } ?> any better for you? Quote Link to comment Share on other sites More sharing options...
DazlerD Posted March 27, 2007 Author Share Posted March 27, 2007 Hi mjlogan Thanks for spending the time with me trying to sort this out. Unfortunatley its still thinking the Sunday is the 24th March. The DST has changed to "1" when we get to date any beyond the questionable dates but the interesting thing is the dates are ok again in the future. "last Sunday" does find the Sunday before. Its only the week that DST is in. Thanks again. ***************************************** Heres the code Im running: $now = strtotime("-70 day", time()); while($now < time()+2000000){ $dst = date('I', $now); echo "####################################<br />"; echo " NEW WEEK<br />"; echo "####################################<br />"; echo " DST = " . $dst . "<br />"; //$today displays todays date (dd/mm/yyyy) if ($dst=='1') { $today = $now-3600; } else { $today = $now; } echo $today."<br />"; echo "Today: ".date('d/m/Y', $today)."<br />"; // Start of week $StartOfWeek = strtotime("last sunday", $today); echo $StartOfWeek."<br />"; echo "Start Of Week: ".date('d/m/Y', $StartOfWeek)."<br />"; // last day of the week Start add 6 days $EndOfWeek = strtotime("+6 day", $StartOfWeek); echo $EndOfWeek."<br />"; echo "End Of Week: ".date('d/m/Y', $EndOfWeek)."<br />"; // start of next week Start add 7 days $StartNextWeek = strtotime("+7 day", $StartOfWeek); echo $StartNextWeek."<br />"; echo "Start Next Week: ".date('d/m/Y', $StartNextWeek)."<br />"; // start of last week Start minus 7 days $StartLastWeek = strtotime("-7 day", $StartOfWeek); echo $StartLastWeek."<br />"; echo "Start Last Week: ".date('d/m/Y', $StartLastWeek)."<br />"; // this is the first possible day you can edit, tomorrow $FirstEditDate = $today+86400; echo $FirstEditDate."<br />"; echo "Tomorrow: ".date('d/m/Y', $FirstEditDate)."<br />"; $now = strtotime("+1 week", $now); } ************************************************************* And heres the results: #################################### NEW WEEK #################################### DST = 0 1174382349 Today: 20/03/2007 1174176000 Start Of Week: 18/03/2007 1174694400 End Of Week: 24/03/2007 1174780800 Start Next Week: 25/03/2007 1173571200 Start Last Week: 11/03/2007 1174468749 Tomorrow: 21/03/2007 #################################### NEW WEEK #################################### DST = 1 1174979949 Today: 27/03/2007 1174777200 Start Of Week: 24/03/2007 1175292000 End Of Week: 30/03/2007 1175378400 Start Next Week: 31/03/2007 1174172400 Start Last Week: 17/03/2007 1175066349 Tomorrow: 28/03/2007 #################################### NEW WEEK #################################### DST = 1 1175584749 Today: 03/04/2007 1175382000 Start Of Week: 01/04/2007 1175900400 End Of Week: 07/04/2007 1175986800 Start Next Week: 08/04/2007 1174780800 Start Last Week: 25/03/2007 1175671149 Tomorrow: 04/04/2007 #################################### NEW WEEK #################################### DST = 1 1176189549 Today: 10/04/2007 1175986800 Start Of Week: 08/04/2007 1176505200 End Of Week: 14/04/2007 1176591600 Start Next Week: 15/04/2007 1175382000 Start Last Week: 01/04/2007 1176275949 Tomorrow: 11/04/2007 #################################### NEW WEEK #################################### DST = 1 1176794349 Today: 17/04/2007 1176591600 Start Of Week: 15/04/2007 1177110000 End Of Week: 21/04/2007 1177196400 Start Next Week: 22/04/2007 1175986800 Start Last Week: 08/04/2007 1176880749 Tomorrow: 18/04/2007 *********************************************************** Ive got some more results based on simply trying to find "last Sunday" from a set date: Passed Date: 23/03/2007 Start Of Week: 18/03/2007 Passed Date: 24/03/2007 Start Of Week: 18/03/2007 Passed Date: 25/03/2007 Start Of Week: 18/03/2007 ( As this is a Sunday it really this needs to be the 25/03/2007) Passed Date: 26/03/2007 Start Of Week: 24/03/2007 Passed Date: 27/03/2007 Start Of Week: 24/03/2007 Passed Date: 28/03/2007 Start Of Week: 24/03/2007 Passed Date: 29/03/2007 Start Of Week: 24/03/2007 Passed Date: 30/03/2007 Start Of Week: 24/03/2007 Passed Date: 31/03/2007 Start Of Week: 24/03/2007 Passed Date: 01/04/2007 Start Of Week: 24/03/2007 Passed Date: 02/04/2007 Start Of Week: 01/04/2007 Quote Link to comment Share on other sites More sharing options...
mjlogan Posted March 27, 2007 Share Posted March 27, 2007 ah, think i get what you are after now. <?php $dst = date('I', time()); if($dst=='1'){ $now = strtotime("-70 day", time()-3600); } else { $now = strtotime("-70 day", time()); } while($now < time()+800000){ echo "####################################\n"; echo " NEW WEEK\n"; echo "####################################\n\n"; //$today displays todays date (dd/mm/yyyy) $today = $now; echo $today."\n"; echo "Today: ".date('\(l\) d/m/Y', $today)."\n\n"; // Start of week if(date('l', $today)!="Sunday"){ $StartOfWeek = strtotime("last sunday", $today); } else { $StartOfWeek = $today; } echo $StartOfWeek."\n"; echo "Week Start: ".date('\(l\) d/m/Y', $StartOfWeek)."\n\n"; // last day of the week Start add 6 days // $EndOfWeek = strtotime("+6 day", $today); // echo $EndOfWeek."\n"; // echo "Six Days Time: ".date('\(l\) d/m/Y', $EndOfWeek)."\n\n"; // start of next week Start add 7 days // $StartNextWeek = strtotime("+7 day", $today); // echo $StartNextWeek."\n"; // echo "Seven Days Time: ".date('\(l\) d/m/Y', $StartNextWeek)."\n\n"; // start of last week Start minus 7 days // $StartLastWeek = strtotime("-7 day", $today); // echo $StartLastWeek."\n"; // echo "Seven Days Ago: ".date('\(l\) d/m/Y', $StartLastWeek)."\n\n"; // this is the first possible day you can edit, tomorrow // $FirstEditDate = $today+86400; // echo $FirstEditDate."\n"; // echo "Tomorrow: ".date('\(l\) d/m/Y', $FirstEditDate)."\n\n"; $now = strtotime("+1 day", $now); } ?> #################################### NEW WEEK #################################### 1174554440 Today: (Thursday) 22/03/2007 1174176000 Week Start: (Sunday) 18/03/2007 #################################### NEW WEEK #################################### 1174640840 Today: (Friday) 23/03/2007 1174176000 Week Start: (Sunday) 18/03/2007 #################################### NEW WEEK #################################### 1174727240 Today: (Saturday) 24/03/2007 1174176000 Week Start: (Sunday) 18/03/2007 #################################### NEW WEEK #################################### 1174810040 Today: (Sunday) 25/03/2007 1174810040 Week Start: (Sunday) 25/03/2007 #################################### NEW WEEK #################################### 1174896440 Today: (Monday) 26/03/2007 1174780800 Week Start: (Sunday) 25/03/2007 #################################### NEW WEEK #################################### 1174982840 Today: (Tuesday) 27/03/2007 1174780800 Week Start: (Sunday) 25/03/2007 #################################### NEW WEEK #################################### Quote Link to comment Share on other sites More sharing options...
DazlerD Posted March 27, 2007 Author Share Posted March 27, 2007 Thanks mjlogan. That sorts that problem: Passed Date: (Friday) 23/03/2007 Start Of Week: (Sunday) 18/03/2007 Passed Date: (Saturday) 24/03/2007 Start Of Week: (Sunday) 18/03/2007 Passed Date: (Sunday) 25/03/2007 Start Of Week: (Sunday) 25/03/2007 Passed Date: (Monday) 26/03/2007 Start Of Week: (Saturday) 24/03/2007 Passed Date: (Tuesday) 27/03/2007 Start Of Week: (Saturday) 24/03/2007 Passed Date: (Wednesday) 28/03/2007 Start Of Week: (Saturday) 24/03/2007 Passed Date: (Thursday) 29/03/2007 Start Of Week: (Saturday) 24/03/2007 Passed Date: (Friday) 30/03/2007 Start Of Week: (Saturday) 24/03/2007 Passed Date: (Saturday) 31/03/2007 Start Of Week: (Saturday) 24/03/2007 Passed Date: (Sunday) 01/04/2007 Start Of Week: (Sunday) 01/04/2007 Passed Date: (Monday) 02/04/2007 Start Of Week: (Sunday) 01/04/2007 Now about the "Last Sunday" getting me a Saturday............ You running PHP version 5.1+? I can see your results are correct. Mine still return Saturday when Im using dates in the week DST is in. Thanks again Darren Quote Link to comment Share on other sites More sharing options...
DazlerD Posted March 27, 2007 Author Share Posted March 27, 2007 mjLogan Ive got the code working, its not perfect but it works!! ******************************************************* //$todaydate sets to to days $todaydate = time(); // If no date passed in if ($PassedStartDate) { $Begin = $PassedStartDate; } else { $Begin = $todaydate; } // sunday $dateCompensator = 0; // 0 if start day is Sunday on my system if (date('l', $Begin)!="Sunday") { $StartOfWeek = strtotime("last sunday", $Begin); // If we are in the DST week bodge it! if(date('l', $StartOfWeek)=="Saturday"){ $StartOfWeek = strtotime("+1 day", $StartOfWeek); } } else { $StartOfWeek = $Begin; } // last day of the week Start add 6 days $EndOfWeek = strtotime("+6 day", $StartOfWeek); // start of next week $StartNextWeek = strtotime("+7 day", $StartOfWeek); // start of last week $StartLastWeek = strtotime("-7 day", $StartOfWeek); // this is the first possible day you can edit, tomorrow $FirstEditDate = strtotime("+1 day", $todaydate); *************************************************** Quote Link to comment Share on other sites More sharing options...
mjlogan Posted March 27, 2007 Share Posted March 27, 2007 There must be some differences in setup somewhere, because the full out from my script was: Today: (Wednesday) 07/03/2007 Week Start: (Sunday) 04/03/2007 Today: (Thursday) 08/03/2007 Week Start: (Sunday) 04/03/2007 Today: (Friday) 09/03/2007 Week Start: (Sunday) 04/03/2007 Today: (Saturday) 10/03/2007 Week Start: (Sunday) 04/03/2007 Today: (Sunday) 11/03/2007 Week Start: (Sunday) 11/03/2007 Today: (Monday) 12/03/2007 Week Start: (Sunday) 11/03/2007 Today: (Tuesday) 13/03/2007 Week Start: (Sunday) 11/03/2007 Today: (Wednesday) 14/03/2007 Week Start: (Sunday) 11/03/2007 Today: (Thursday) 15/03/2007 Week Start: (Sunday) 11/03/2007 Today: (Friday) 16/03/2007 Week Start: (Sunday) 11/03/2007 Today: (Saturday) 17/03/2007 Week Start: (Sunday) 11/03/2007 Today: (Sunday) 18/03/2007 Week Start: (Sunday) 18/03/2007 Today: (Monday) 19/03/2007 Week Start: (Sunday) 18/03/2007 Today: (Tuesday) 20/03/2007 Week Start: (Sunday) 18/03/2007 Today: (Wednesday) 21/03/2007 Week Start: (Sunday) 18/03/2007 Today: (Thursday) 22/03/2007 Week Start: (Sunday) 18/03/2007 Today: (Friday) 23/03/2007 Week Start: (Sunday) 18/03/2007 Today: (Saturday) 24/03/2007 Week Start: (Sunday) 18/03/2007 Today: (Sunday) 25/03/2007 Week Start: (Sunday) 25/03/2007 Today: (Monday) 26/03/2007 Week Start: (Sunday) 25/03/2007 Today: (Tuesday) 27/03/2007 Week Start: (Sunday) 25/03/2007 Today: (Wednesday) 28/03/2007 Week Start: (Sunday) 25/03/2007 Today: (Thursday) 29/03/2007 Week Start: (Sunday) 25/03/2007 Today: (Friday) 30/03/2007 Week Start: (Sunday) 25/03/2007 Today: (Saturday) 31/03/2007 Week Start: (Sunday) 25/03/2007 Today: (Sunday) 01/04/2007 Week Start: (Sunday) 01/04/2007 Today: (Monday) 02/04/2007 Week Start: (Sunday) 01/04/2007 Today: (Tuesday) 03/04/2007 Week Start: (Sunday) 01/04/2007 Today: (Wednesday) 04/04/2007 Week Start: (Sunday) 01/04/2007 Today: (Thursday) 05/04/2007 Week Start: (Sunday) 01/04/2007 all Sundays! Running: PHP Version 5.1.6 Quote Link to comment Share on other sites More sharing options...
DazlerD Posted March 27, 2007 Author Share Posted March 27, 2007 I found a DST bug on the php site which is fixed in version 5.1. Im running 4.3.2 Quote Link to comment Share on other sites More sharing options...
mjlogan Posted March 27, 2007 Share Posted March 27, 2007 ah cool, guessing that solves the problem. Quote Link to comment Share on other sites More sharing options...
DazlerD Posted March 27, 2007 Author Share Posted March 27, 2007 As its onvly concerned with web app and only affects this week, I dont think we will bother upgraded PHP. Ill just leave my fix on there. Thanks again for all your help Darren 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.