Jump to content

Finding date for selected day in previous week


Fenhopi

Recommended Posts

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!

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>

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

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()).

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.