<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Antanova Ltd. &#187; snippet</title>
	<atom:link href="http://antanova.com/tags/snippet/feed" rel="self" type="application/rss+xml" />
	<link>http://antanova.com</link>
	<description>We make excellent websites</description>
	<lastBuildDate>Tue, 30 Mar 2010 09:08:11 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Code bits: PHP date year box script</title>
		<link>http://antanova.com/blog/code-bits/php-date-year-box-script</link>
		<comments>http://antanova.com/blog/code-bits/php-date-year-box-script#comments</comments>
		<pubDate>Thu, 13 Nov 2008 15:44:00 +0000</pubDate>
		<dc:creator>Jason C</dc:creator>
				<category><![CDATA[Code-bits]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[snippet]]></category>

		<guid isPermaLink="false">http://antanova.wordpress.com/2008/11/13/code-bits-php-date-year-box-script/</guid>
		<description><![CDATA[Code bits: PHP year box script. Create a dropdown form box listing all years from a certain date to the current year.]]></description>
			<content:encoded><![CDATA[<p>Creating a warranty registration form for the proud owners of a new LCD panel should have been a very straightforward job. Well, actually it was, but that sort of interrupts the flow of this post a bit, so I’ll skim over that inconvenient fact.</p>
<p>For the ‘date of purchase’ field, I simply added the day and months items as <code>&lt;select&gt;</code> form controls. Then I got to the ‘year’ box, and realised that soon we’ll be leaving <a href="http://en.wikipedia.org/wiki/2008">2008</a> behind like a piece of temporal rubbish, and embracing the glistening newborn that will be 2009. I know the client wouldn’t really appreciate having to come back to me a month after his site goes live just so I can add a new year to the form, so I decided on the only sensible course of action a <a href="http://www.antanova.com/">quality web designer</a> like me could take, and made a super-simple php script to write the year into the form.</p>
<p>Here’s the php function:</p>
<blockquote>
<pre><code>function writePurchaseYear()
{
    $currentDate = getDate();
    $currentYear = $currentDate['year'];
    $startYear = 2008;
    $output = "&lt;option value=\"2008\"&gt;2008&lt;/option&gt;\n";

    if($currentYear - $startYear &gt; 0)
    {
        for($i = $currentYear; $i &gt;= $startYear; $i--)
        {
            $output = $output . "&lt;output value=\"$i\"&gt;$i&lt;/option&gt;\n";
        }
    }
    echo $output;
}

</code></pre>
</blockquote>
<p>So, put that somewhere on the page that’s going to use it, and then, where you need the actual form control to be on the page, you need to put:</p>
<blockquote>
<pre><code>&lt;select name="purchaseyear" id="purchaseyear"&gt;
    &lt;option selected&gt;----&lt;/option&gt;
    &lt;?php writePurchaseYear();?&gt;
&lt;/select&gt;

</code></pre>
</blockquote>
<p>So there you have it. HTH, and all that.</p>
]]></content:encoded>
			<wfw:commentRss>http://antanova.com/blog/code-bits/php-date-year-box-script/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
