leszer Posted March 1, 2012 Share Posted March 1, 2012 So I was wondering if anyone could come up with a good way of having a drop down box list the dates of the previous week starting from Saturday. The dates would need to go from Saturday to the coming/current friday. Or would I just be better off having it list the days 'Saturday' to 'Friday'. Any thoughts? Quote Link to comment https://forums.phpfreaks.com/topic/258052-drop-down-list-of-days-in-the-current-week/ Share on other sites More sharing options...
ManiacDan Posted March 1, 2012 Share Posted March 1, 2012 $date = strtotime('-1 saturday'); do { echo date('l F jS, Y', $date) . "\n"; } while ( ($date += (60*60*24)) && $date <= strtotime('next friday') ); Quote Link to comment https://forums.phpfreaks.com/topic/258052-drop-down-list-of-days-in-the-current-week/#findComment-1322777 Share on other sites More sharing options...
Psycho Posted March 1, 2012 Share Posted March 1, 2012 $date = strtotime('-1 saturday'); do { echo date('l F jS, Y', $date) . "\n"; } while ( ($date += (60*60*24)) && $date <= strtotime('next friday') ); There's a bug in that. ON a Saturday it would create two weeks of values. I think you'd need to check if the current day is friday and use that instead of "next friday" EDIT: No I got that backward. If it is a saturday then it needs to start on the current day. So, it is the $date value that needs to be modified. Quote Link to comment https://forums.phpfreaks.com/topic/258052-drop-down-list-of-days-in-the-current-week/#findComment-1322799 Share on other sites More sharing options...
leszer Posted March 1, 2012 Author Share Posted March 1, 2012 So... if (date(strtotime( 'saturday'))) $date=strtotime('saturday'); else $date=strtotime('-1 saturday'); ?? Edit: forgot to put php in code. $date = strtotime('-1 saturday'); do { echo date('l F jS, Y', $date) . "\n"; } while ( ($date += (60*60*24)) && $date <= strtotime('next friday') ); There's a bug in that. ON a Saturday it would create two weeks of values. I think you'd need to check if the current day is friday and use that instead of "next friday" EDIT: No I got that backward. If it is a saturday then it needs to start on the current day. So, it is the $date value that needs to be modified. Quote Link to comment https://forums.phpfreaks.com/topic/258052-drop-down-list-of-days-in-the-current-week/#findComment-1322803 Share on other sites More sharing options...
Psycho Posted March 1, 2012 Share Posted March 1, 2012 OK, I played around with that code a bit and run into other problems due to anomalies with the timestamps - daylight savings time would definitely be an issue. I have done some testing and the following code appears to work. I tested with the start day being the first day of the period, within the period and the last day of the period. You should do some more extensive testing. //If today is NOT saturday, set start date to last saturday, //else set to today $start_date = (date('N')!=6) ? strtotime('-1 saturday') : time(); //Create list of the seven days starting from start date for($day=0; $day<7; $day++) { $date = strtotime("+{$day} days", $start_date); echo date('l F jS, Y', $date) . "<br>\n"; } Quote Link to comment https://forums.phpfreaks.com/topic/258052-drop-down-list-of-days-in-the-current-week/#findComment-1322813 Share on other sites More sharing options...
leszer Posted March 2, 2012 Author Share Posted March 2, 2012 That works perfect. Excellent even. Thank you both very much! Closing the topic as solved. Quote Link to comment https://forums.phpfreaks.com/topic/258052-drop-down-list-of-days-in-the-current-week/#findComment-1323092 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.