Jump to content

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


Jackanape

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"))

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.