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!

Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.