dc_jt Posted May 31, 2007 Share Posted May 31, 2007 Hi Ive got the following drop down which works perfectly, although the default date is set to todays date. Could you please advise me on how to set it to show -- -- ---- instead of 31 05 2007? Thanks First part which sets is to todays date /***** End Date *****/ $Endtoday = getdate(); $Endday = $Endtoday['mday']; $Endyear = $today['year']; //To default to yesterday: //$day -= 1; //Otherwise, todays date: $Endday == 1; $Endmonth = $Endtoday['mon']; $Endmtharr = array("January","February","March","April","May","June","July","August","September","October","November","December"); $Enddate = str_replace(" ","/",formatDate($oObj->end_date)); $EndaDate = explode("/",$Enddate); $EndaYear = (int)$EndaDate[2]; $EndaMonth =(int)$EndaDate[1]; $EndaDay = (int)$EndaDate[0]; /************************/ The date loop <tr> <tr> <td width="28%"><strong>End Date</strong></td> <td><select name="Endsdated" class="fmgreynormal"> <? for ($i=1;$i<=31;$i++) {?><? echo "<option value=\"$i\""; if ($_GET['iOfferId'] && formatDate($oObj->end_date) != '00/00/0000') { if ($i == $EndaDay) echo " selected"; echo ">".printf(">%02d</option>",$i); } else { if ($i == $Endday) echo " selected"; echo ">".printf(">%02d</option>",$i); } } ?> </select> <select name="Endsdatem" class="fmgreynormal"> <? for ($i=1;$i<=12;$i++) {?><? echo "<option value=\"$i\""; if ($_GET['iOfferId'] && formatDate($oObj->end_date) != '00/00/0000') { if ($i == $EndaMonth) echo " selected"; echo ">".printf(">%02d</option>",$i); } else { if ($i == $Endmonth) echo " selected"; echo ">".printf(">%02d</option>",$i); } } ?> </select> <select name="Endsdatey" class="fmgreynormal"> <?php for ($i=date('Y')-1;$i<=date('Y')+2;$i++) {?> <?php echo "<option value=\"$i\""; if ($_GET['iOfferId'] && formatDate($oObj->end_date) != '00/00/0000') { if ($i == $EndaYear) echo " selected"; echo ">$i</option>"; } else { if ($i == $Endyear) echo " selected"; echo ">$i</option>"; } } ?> </select> </td> </tr> </td> </tr> Quote Link to comment https://forums.phpfreaks.com/topic/53709-setting-default-date-drop-down-to/ Share on other sites More sharing options...
dc_jt Posted May 31, 2007 Author Share Posted May 31, 2007 Anyone??? Quote Link to comment https://forums.phpfreaks.com/topic/53709-setting-default-date-drop-down-to/#findComment-265456 Share on other sites More sharing options...
neel_basu Posted May 31, 2007 Share Posted May 31, 2007 Although I didn't understand your code well(If everything is same in both if and else then why you are using if ?????) --------------------------------------------------------- You can try something like this <?php for ($i=date('Y')-1;$i<=date('Y')+2;$i++) { echo "<option value=\"$i\">$i</option>"; } echo "<option value=\"--\" selected>--</option>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/53709-setting-default-date-drop-down-to/#findComment-265478 Share on other sites More sharing options...
dc_jt Posted May 31, 2007 Author Share Posted May 31, 2007 They are not the same. This gets the default (todays date) $today = getdate(); $day = $today['mday']; //To default to yesterday: //$day -= 1; //Otherwise, todays date: $day == 1; $month = $today['mon']; $mtharr = array("January","February","March","April","May","June","July","August","September","October","November","December"); $year = $today['year']; This gets the date set in the database (for example if you are editing something and the end date has already been set) $date = str_replace(" ","/",formatDate($oObj->start_date)); $aDate = explode("/",$date); $aYear = (int)$aDate[2]; $aMonth =(int)$aDate[1]; $aDay = (int)$aDate[0]; formatDate($oObj->start_date basically takes the date from the mysql database and turns it into a dd/mm/yyyy format Quote Link to comment https://forums.phpfreaks.com/topic/53709-setting-default-date-drop-down-to/#findComment-265486 Share on other sites More sharing options...
dc_jt Posted May 31, 2007 Author Share Posted May 31, 2007 An alternative way I have done for the year is this: <select name="Endsdatey" class="fmgreynormal"> <option value="0000" <? if ($form_sdatey == '0000'){ echo "selected='selected'";}?>>----</option> <option value="2007" <? if ($form_sdatey == '2007'){ echo "selected='selected'";}?>>2007</option> <option value="2008" <? if ($form_sdatey == '2008'){ echo "selected='selected'";}?>>2008</option> <option value="2009" <? if ($form_sdatey == '2009'){ echo "selected='selected'";}?>>2009</option> <option value="2010" <? if ($form_sdatey == '2010'){ echo "selected='selected'";}?>>2010</option> <option value="2011" <? if ($form_sdatey == '2011'){ echo "selected='selected'";}?>>2011</option> <option value="2012" <? if ($form_sdatey == '2012'){ echo "selected='selected'";}?>>2012</option> <option value="2013" <? if ($form_sdatey == '2013'){ echo "selected='selected'";}?>>2013</option> </select> However when I get to 2013 Ill have to redo the code, anyway I can put this into a loop? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/53709-setting-default-date-drop-down-to/#findComment-265496 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.