<?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>*drawlogic &#187; date</title>
	<atom:link href="http://drawlogic.com/tag/date/feed/" rel="self" type="application/rss+xml" />
	<link>http://drawlogic.com</link>
	<description>interactive and game development technologies for the web - flash, flex, unity3d, silverlight, javascript</description>
	<lastBuildDate>Thu, 22 Dec 2011 21:55:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>HOWTO: Using AS3 to Get Age from Birthday (Birthdate)</title>
		<link>http://drawlogic.com/2008/04/16/howto-using-as3-to-get-age-from-birthday-birthdate/</link>
		<comments>http://drawlogic.com/2008/04/16/howto-using-as3-to-get-age-from-birthday-birthdate/#comments</comments>
		<pubDate>Wed, 16 Apr 2008 21:17:43 +0000</pubDate>
		<dc:creator>drawk</dc:creator>
				<category><![CDATA[ACTIONSCRIPT]]></category>
		<category><![CDATA[ACTIONSCRIPT3]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[DEVELOPMENT]]></category>
		<category><![CDATA[FLASH]]></category>
		<category><![CDATA[PROGRAMMING]]></category>
		<category><![CDATA[TECHNOLOGY]]></category>
		<category><![CDATA[age]]></category>
		<category><![CDATA[date]]></category>
		<category><![CDATA[utility]]></category>

		<guid isPermaLink="false">http://drawk.wordpress.com/?p=188</guid>
		<description><![CDATA[I had to implement a get age method for something we were working on. I was surprised to not find an AS3 version easily, so busted one out. I thought maybe this would be in as3corelib but nope. So posting this in case anyone else is looking for a get age script in AS3. It [...]]]></description>
			<content:encoded><![CDATA[<p>I had to implement a get age method for something we were working on.  I was surprised to not find an AS3 version easily, so busted one out. I <a href="http://code.google.com/p/as3corelib/source/browse/trunk/src/com/adobe/utils/DateUtil.as" target="_blank">thought maybe this would be in as3corelib</a> but nope.  So posting this in case anyone else is looking for a get age script in AS3. It was quick so any improvements just post them. It will be added to my utilities classes on google code soon it is in quick form so you can jsut plop in an .fla or a class.</p>
<p>The pseudo code is the same for getting age in any language.  Get current date, get birthdate to compare.  Subtract the current years from the birthday years, then subtract one more year if the day or month is less than today&#8217;s day and month.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> calculateAge<span style="color: #009900;">&#40;</span>birthdate<span style="color: #339933;">:</span>Date<span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span>Number <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> dtNow<span style="color: #339933;">:</span>Date <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Date<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #006600; font-style: italic;">// gets current date</span>
    <span style="color: #003366; font-weight: bold;">var</span> currentMonth<span style="color: #339933;">:</span>Number <span style="color: #339933;">=</span> dtNow.<span style="color: #660066;">getMonth</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> currentDay<span style="color: #339933;">:</span>Number <span style="color: #339933;">=</span> dtNow.<span style="color: #660066;">getDay</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> currentYear<span style="color: #339933;">:</span>Number <span style="color: #339933;">=</span> dtNow.<span style="color: #660066;">getFullYear</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #003366; font-weight: bold;">var</span> bdMonth<span style="color: #339933;">:</span>Number <span style="color: #339933;">=</span> birthdate.<span style="color: #660066;">getMonth</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> bdDay<span style="color: #339933;">:</span>Number <span style="color: #339933;">=</span> birthdate.<span style="color: #660066;">getDay</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> bdYear<span style="color: #339933;">:</span>Number <span style="color: #339933;">=</span> birthdate.<span style="color: #660066;">getFullYear</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">// get the difference in years</span>
    <span style="color: #003366; font-weight: bold;">var</span> years<span style="color: #339933;">:</span>Number <span style="color: #339933;">=</span> dtNow.<span style="color: #660066;">getFullYear</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> birthdate.<span style="color: #660066;">getFullYear</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #006600; font-style: italic;">// subtract another year if we're before the</span>
    <span style="color: #006600; font-style: italic;">// birth day in the current year</span>
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>currentMonth <span style="color: #339933;">&lt;</span> bdMonth <span style="color: #339933;">||</span> <span style="color: #009900;">&#40;</span>currentMonth <span style="color: #339933;">==</span> bdMonth <span style="color: #339933;">&amp;&amp;</span> currentDay <span style="color: #339933;">&lt;</span> bdDay<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        years<span style="color: #339933;">--;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000066; font-weight: bold;">return</span> years<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> dateStringToObject<span style="color: #009900;">&#40;</span>dateString<span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span>Date <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> date_ar <span style="color: #339933;">=</span> dateString.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;/&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">new</span> Date<span style="color: #009900;">&#40;</span>date_ar<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>date_ar<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">-</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">,</span>date_ar<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> dateNow<span style="color: #339933;">:</span>Date <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Date<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> checkDate<span style="color: #339933;">:</span>String <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;11/25/1976&quot;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> dateBirthday<span style="color: #339933;">:</span>Date <span style="color: #339933;">=</span> dateStringToObject<span style="color: #009900;">&#40;</span>checkDate<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
trace<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;dateNow = &quot;</span><span style="color: #339933;">+</span>dateNow<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
trace<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;dateBirthday = &quot;</span><span style="color: #339933;">+</span>dateBirthday<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
trace<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;age = &quot;</span><span style="color: #339933;">+</span>calculateAge<span style="color: #009900;">&#40;</span>dateBirthday<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://drawlogic.com/2008/04/16/howto-using-as3-to-get-age-from-birthday-birthdate/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

