nbarone Posted July 14, 2009 Share Posted July 14, 2009 I am wondering how I would make a <select> box in php, that goes from June 30th 2009 (5/30/09) to (dynamic date) and shows only TUESDAYS. it should be formatted like so: <option value="2009/05/30">June 30th, 2009</option> Thanks! Link to comment https://forums.phpfreaks.com/topic/165974-select-form-dates-tuesdays/ Share on other sites More sharing options...
rhodesa Posted July 14, 2009 Share Posted July 14, 2009 <?php $start = strtotime('2009-05-27'); $end = strtotime('2009-07-12'); $dow = 2; //1 = Mon, 2 = Tues, 3 = Wed, etc $offset = $dow - date('N',$start); if($offset < 0) $offset += 7; print '<select name="date">'; for($date = strtotime('+'.$offset.' days',$start);$date <= $end;$date = strtotime('+1 week',$date)){ printf('<option value="%s">%s</option>',$date,date('F jS Y',$date)); } print '</select>'; ?> Link to comment https://forums.phpfreaks.com/topic/165974-select-form-dates-tuesdays/#findComment-875378 Share on other sites More sharing options...
phporcaffeine Posted July 14, 2009 Share Posted July 14, 2009 <?php $startDate = array('06/30/2009', strtotime('June 30th 2009')); $endDate = array('08/30/2009', strtotime('August 30th 2009')); $inc = $startDate[1]; while ($inc < $endDate[1]) { $inc = $inc + 604800; $options[] = "<option value='" . date('Y/m/d', $inc) . "'>" . date('F jS, Y', $inc) . "</option>"; } ?> <select name='date' id='date'> <option value='<?=$startDate[0];?>'><?=date ('F jS, Y', $startDate[1]);?></option> <?php foreach ($options as $value) { echo $value . "\n"; } ?> <option value='<?=$endDate[0];?>'><?=date ('F jS, Y', $endDate[1]);?></option> </select> Link to comment https://forums.phpfreaks.com/topic/165974-select-form-dates-tuesdays/#findComment-875384 Share on other sites More sharing options...
genericnumber1 Posted July 14, 2009 Share Posted July 14, 2009 <?php define('SECONDS_PER_WEEK', 604800); $startDate = mktime(0, 0, 0, 6, 30, 2009); $endDate = $startDate + (SECONDS_PER_WEEK * 10); // 10 weeks past $startDate for($date = $startDate; $date <= $endDate; $date += SECONDS_PER_WEEK) { printf('<option value="%s">%s</option>', date('n/j/Y', $date), date('F jS, Y', $date)); } ?> Doubt you needed this many answers, but I wrote it and dammit if I'm going to let it go to waste. Link to comment https://forums.phpfreaks.com/topic/165974-select-form-dates-tuesdays/#findComment-875386 Share on other sites More sharing options...
rhodesa Posted July 14, 2009 Share Posted July 14, 2009 <?php $start = strtotime('2009-05-27'); $end = strtotime('2009-07-12'); $dow = 2; //1 = Mon, 2 = Tues, 3 = Wed, etc $offset = $dow - date('N',$start); if($offset < 0) $offset += 7; print '<select name="date">'; for($date = strtotime('+'.$offset.' days',$start);$date <= $end;$date = strtotime('+1 week',$date)){ printf('<option value="%s">%s</option>',$date,date('F jS Y',$date)); } print '</select>'; ?> oh yeah...this line: printf('<option value="%s">%s</option>',$date,date('F jS Y',$date)); should be: printf('<option value="%s">%s</option>',date('Y/m/d',$date),date('F jS Y',$date)); Link to comment https://forums.phpfreaks.com/topic/165974-select-form-dates-tuesdays/#findComment-875393 Share on other sites More sharing options...
cunoodle2 Posted July 14, 2009 Share Posted July 14, 2009 I am wondering how I would make a <select> box in php, that goes from June 30th 2009 (5/30/09) to (dynamic date) and shows only TUESDAYS. it should be formatted like so: <option value="2009/05/30">June 30th, 2009</option> Thanks! Am I the only one on here that noticed that June is the 6th month and not the 5th?? "June 30th 2009 (5/30/09)" Link to comment https://forums.phpfreaks.com/topic/165974-select-form-dates-tuesdays/#findComment-875411 Share on other sites More sharing options...
rhodesa Posted July 14, 2009 Share Posted July 14, 2009 details....details.... Link to comment https://forums.phpfreaks.com/topic/165974-select-form-dates-tuesdays/#findComment-875414 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.