On Fri, 2007-02-02 at 19:02 -0600, Richard Lynch wrote:
> On Fri, February 2, 2007 9:11 am, Dan Shirah wrote:
> > I am trying to populate a dropdown list to contain the current year to
> > 10
> > years in the future.  Below is the code I'm using:
> >
> > <?PHP
> >   for ($y=0;$y<=10;$y++) {
> >   $years=date <http://php.net/date>('Y')+$y;
> >   $short_years=date <http://php.net/date>('y')+$y;
> >   echo "$short_years";
> >   echo "<option value=\"$short_years\">$years</option>";
> >   }
> > ?>
> > I want the selection value to be 2007, 2008, 2009, 2010....  and the
> > $years
> > accomplishes this.  Howeverm I want the option value to be the two
> > digit
> > year ex. 07, 08, 09, 10...the $short_years semi accomplishes
> > this....instead
> > of getting 07, 08, 08, 10 I get 7, 8, 9, 10...how can I get it to
> > output the
> > two year for 07, 08, 09 without it cutting off the zero?
> 
> for ($year = date('Y'); $year <= date('Y') + 10; $year++){
>   $short_year = $year - 2000;
>   echo "<option value=\"$short_year\">$year</option>\n";
> }
> 
> Using the 2-digit year as your value is almost for sure a really Bad
> Idea, unless you are dealing with legacy software that absolutely
> needs it...

Sorry Richard, you solution fails since he wants to retain the leading
zeros on the 2 digit years. Using subtraction and not formatting the
result will result in the loss of the 0 in 07. Also, why call the date()
function 10 times by embedding it in the loop's terminate condition?

Cheers,
Rob.
-- 
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for       |
| creating re-usable components quickly and easily.          |
`------------------------------------------------------------'

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to