Re: Year
| From: | Robert Cummings | Date: | Fri, 02 Feb 2007 15:21:39 +0000 |
| Subject: | Re: Year | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-248195@lists.php.net to get a copy of this message | ||
On Fri, 2007-02-02 at 10:11 -0500, Dan Shirah wrote:
> Hello all,
>
> 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?
<?php
$year = date( 'Y' );
for( $i = 0; $i < 10; $i++ )
{
$iYear = substr( (string)($year + 1), 2 );
echo '<option
value="'.$iYear.'">'.$iYear.'</option>';
}
?>
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. |
`------------------------------------------------------------'