Fenhopi Posted November 6, 2010 Share Posted November 6, 2010 Hi, I have a select box that has every week day as an option. When a user picks "Monday" and submits the form I want to echo the date of monday last week. And if he picks tuesday, I want it to give the date of Tuesday last week, on so on. How would I do that? Thank you in advance! Link to comment https://forums.phpfreaks.com/topic/217958-finding-date-for-selected-day-in-previous-week/ Share on other sites More sharing options...
Yucky Posted November 6, 2010 Share Posted November 6, 2010 Just to be clear, if they selected Tuesday, would you want last week's Tuesday or the last Tuesday gone? Link to comment https://forums.phpfreaks.com/topic/217958-finding-date-for-selected-day-in-previous-week/#findComment-1131188 Share on other sites More sharing options...
Fenhopi Posted November 7, 2010 Author Share Posted November 7, 2010 The last Tuesday gone. Link to comment https://forums.phpfreaks.com/topic/217958-finding-date-for-selected-day-in-previous-week/#findComment-1131219 Share on other sites More sharing options...
BlueSkyIS Posted November 7, 2010 Share Posted November 7, 2010 what if it's Tuesday when they pick Tuesday? Link to comment https://forums.phpfreaks.com/topic/217958-finding-date-for-selected-day-in-previous-week/#findComment-1131226 Share on other sites More sharing options...
Yucky Posted November 7, 2010 Share Posted November 7, 2010 what if it's Tuesday when they pick Tuesday? Last week's Tuesday. Link to comment https://forums.phpfreaks.com/topic/217958-finding-date-for-selected-day-in-previous-week/#findComment-1131239 Share on other sites More sharing options...
jcbones Posted November 7, 2010 Share Posted November 7, 2010 Tested. <?php if(isset($_GET['submit'])) { $day = $_GET['day']; echo date('l F jS, Y',strtotime('last ' . $day)); } ?> <form action=""> <select name="day"> <option>Monday</option> <option>Tuesday</option> <option>Wednesday</option> <option>Thursday</option> <option>Friday</option> <option>Saturday</option> <option>Sunday</option> </select> <input type="submit" name="submit" value="submit"/> </form> Link to comment https://forums.phpfreaks.com/topic/217958-finding-date-for-selected-day-in-previous-week/#findComment-1131253 Share on other sites More sharing options...
Fenhopi Posted November 8, 2010 Author Share Posted November 8, 2010 Thank you very much! I get this error though: Warning: date() [function.date]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/Berlin' for 'CET/1.0/no DST' instead in Link to comment https://forums.phpfreaks.com/topic/217958-finding-date-for-selected-day-in-previous-week/#findComment-1131744 Share on other sites More sharing options...
jcbones Posted November 9, 2010 Share Posted November 9, 2010 That is not an error, just a warning. Just add: date_default_timezone_set() date_default_timezone_set('America/New_York'); To the top of your script. Link to comment https://forums.phpfreaks.com/topic/217958-finding-date-for-selected-day-in-previous-week/#findComment-1132019 Share on other sites More sharing options...
salathe Posted November 9, 2010 Share Posted November 9, 2010 Or, read the message since both options for resolving the cause of the warning (and the reason for it) are very clearly stated. Use that function to set a default timezone at runtime, or use the date.timezone INI setting (in httpd.conf, php.ini, a user.ini, .htaccess or via ini_set()). Link to comment https://forums.phpfreaks.com/topic/217958-finding-date-for-selected-day-in-previous-week/#findComment-1132161 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.