Jump to content

[SOLVED] Pulldown menu limited to JUST the past week?


Recommended Posts

Hi!

 

I've always been helped here, so here I return, probably with a silly question, but I can't seem to hammer this out--maybe because I just finished a big timezone conversion function?--and perhaps my head is just into it too deep...

As I've said before, I'm something of a simpleton when it comes to "whipping" out code...it takes me awhile... :D

 

I'm trying to put together a Pulldown menu containing the last week's dates for a form I'm putting together.  The problem is keeping it limited to JUST the past week...I can get the whole month in, but not just the past week...is there a good place I should begin looking? A function I may have missed?

If you trust the strtotime function, you can use it....

 

$days = array();
$days[] = date("Y-m-d");

for ($i = 1; $i <= 6; $i++) {
$days[] = date("Y-m-d", strtotime("-" . $i . " day"));
}

$html = '
<select size="1" name="dates">';

foreach ($days as $day) {
$html .= '
	<option>' . $day . '</option>';
}

$html .= '
</option>';

echo $html;

 

Or, if you don't trust strtotime, you can replicate the same behavior with mktime...

 

mktime(null, null, null, date("m"), date("d") - $i, date("Y"))

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.