Jackanape Posted January 28, 2008 Share Posted January 28, 2008 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... 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? Link to comment https://forums.phpfreaks.com/topic/88233-solved-pulldown-menu-limited-to-just-the-past-week/ Share on other sites More sharing options...
hitman6003 Posted January 28, 2008 Share Posted January 28, 2008 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")) Link to comment https://forums.phpfreaks.com/topic/88233-solved-pulldown-menu-limited-to-just-the-past-week/#findComment-451458 Share on other sites More sharing options...
Jackanape Posted January 28, 2008 Author Share Posted January 28, 2008 ooof...how embarrassing...I was just using strtotime() as a solution for someone else's post, and there it was in front of me the whole time... Thanks for opening my eyes! Link to comment https://forums.phpfreaks.com/topic/88233-solved-pulldown-menu-limited-to-just-the-past-week/#findComment-451532 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.