dc_jt Posted May 1, 2007 Share Posted May 1, 2007 Hi Probably a simple question but I have a date drop down which displays the days 1-31, however 1-9 are displayed 1,2,3,4,5,6,7,8,9 rather than 01, 02, 03, 04, 05, 06, 07, 08, 09. So how do I get the 0 in front of each number? Here is my code: <td width="28%"><strong>Article Date</strong></td> <td><select name="sdated"> <? for ($i=1;$i<=31;$i++) {?><? echo "<option value=\"$i\""; if ($_GET['iNewsId'] && $oNewsArticle->formatted_article_date != '00/00/0000') { if ($i == $aDay) echo " selected"; echo ">$i</option>"; } else { if ($i == $day) echo " selected"; echo ">$i</option>"; } } ?> </select> <select name="sdatem"> <? for ($i=1;$i<=12;$i++) {?><? echo "<option value=\"$i\""; if ($_GET['iNewsId'] && $oNewsArticle->formatted_article_date != '00/00/0000') { if ($i == $aMonth) echo " selected"; echo ">$i</option>"; } else { if ($i == $month) echo " selected"; echo ">$i</option>"; } } ?> </select> <select name="sdatey"> <?php for ($i=date('Y');$i<=date('Y')+2;$i++) {?> <?php echo "<option value=\"$i\""; if ($_GET['iNewsId'] && $oNewsArticle->formatted_article_date != '00/00/0000') { if ($i == $aYear) echo " selected"; echo ">$i</option>"; } else { if ($i == $year) echo " selected"; echo ">$i</option>"; } } ?> </select> </td> </tr> </td> </tr> Link to comment https://forums.phpfreaks.com/topic/49456-solved-adding-a-0-before-1-9-in-date-drop-down/ Share on other sites More sharing options...
taith Posted May 1, 2007 Share Posted May 1, 2007 use str_pad()... prolly your best choice... http://us.php.net/manual/en/function.str-pad.php Link to comment https://forums.phpfreaks.com/topic/49456-solved-adding-a-0-before-1-9-in-date-drop-down/#findComment-242385 Share on other sites More sharing options...
trq Posted May 1, 2007 Share Posted May 1, 2007 Or... printf(">%02d</option>",$i); Link to comment https://forums.phpfreaks.com/topic/49456-solved-adding-a-0-before-1-9-in-date-drop-down/#findComment-242388 Share on other sites More sharing options...
dc_jt Posted May 1, 2007 Author Share Posted May 1, 2007 Thanks a lot, I used this method and it worked Or... printf(">%02d</option>",$i); Link to comment https://forums.phpfreaks.com/topic/49456-solved-adding-a-0-before-1-9-in-date-drop-down/#findComment-242397 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.