:blogpost: true :date: 2002-11-10 15:32 :author: Quantum :category: WPArchive :tags: PHP, Software :slug: finally-it-works :status: published ################ Finally It Works ################ I think I have finally completed my age progression bar script. I have tested it and it seems to work ok. This is why I'm now allowing you lucky people out there to get your hands on it. .. code-block:: php :caption: Age Progression Bar :linenos: # ################################################################################ //Fill in your brithday information //If you were born before 1st Jan 1970 this script will not work //This is because its based on a unix timestamp taken from that date to the present //The day you were born [1-31{where appropriate}(no leading zeros)] $Bday = 16; //The month you were born [1-12 (no leading zeros)] $Bmonth = 1; //The year you were born 4-digits (ie 1980) $Byear = 1980; //Your Name (ie John Smith or John) $Name = Bob; ################################################################################ #####################DONT EDIT BEYOND THIS LINE################################# ################################################################################ ################################################################################ # -------------------------getAge Function-------------------------------------# # getAge will accept the following variables # # getAge('September 3rd, 1980'); # # getAge('1980-9-3'); # # getAge('1980/09/03'); # ################################################################################ function getAge($_dob) { $dob = date("Y-m-d",strtotime($_dob)); $ageparts = explode("-",$dob); // calculate age $age = date("Y-m-d")-$dob; // return their age (or their age minus one year if it's not their birthday yet, in current year return (date("nd") < $ageparts[1].str_pad($ageparts[2],2,'0',STR_PAD_LEFT)) ? $age-=1 : $age; } ################################################################################# ################################################################################# ################################################################################# //Get details of todays date for calculation purposes $today = getdate(); $Tday = $today['mday']; $Tmonth = $today['mon']; $Tyear = $today['year']; // this is today (create date string) $nowdate = mktime(0,0,0,date("m"),date("d"),date("Y"),0); // this is my birthday (create date string) $birthday = mktime(0,0,0,"$Bmonth","$Bday","$Byear",0); // calculate my age in years $age = getAge('1982-11-7'); // calculate my next age in years $nextage = $age + 1; // my next birthday (create date string) $nextbirthday = mktime(0,0,0,"$Bmonth","$Bday",date("Y"),0); // if $nextbirtday is in the past, add 1 year to $nextbirthday if ($nextbirthday<$nowdate) { $nextbirthday=$nextbirthday+(60*60*24*365); } // calculate the remaining day's till my next birthday $DaysToGo=intval(($nextbirthday-$nowdate)/(60*60*24)); ################################################################################ # This next section of code controls the results to be output # ################################################################################ // The output bar is 100px wide and represents 365 days. // Each pixel represents 3.65 days $OnePercent = 3.65; // Width of progres to go $Width2 = ($DaysToGo/$OnePercent); // Percentage complete $perc=100-($Width2); // Width of current progress $Width1 = (100 - $Width2); // Output the calculated percentage to 4 decimal places $prcnt = substr($perc,0,6); // Change variables to display altered output on Birthday if(($Tday == $Bday) && ($Tmonth == $Bmonth)) { $DTG = "365"; $StartGreeting = 'Happy Birthday
'; $Person = $Name; $EndGreeting = '
'; } else { $DTG = "$DaysToGo"; $StartGreeting =""; $Person =""; $EndGreeting =""; } ?> # ################################################################################## # # # #Age Progession Bar # # # # ?>
Age Progression Bar
Current Age:
Days till :
Trasnsition Progress:
%
px">

# ?> .. code-block:: css :caption: Age Progression Bar Stylesheet :linenos: .APB { background-color:#f9f9f9; width:124px; margin:0px; border:1px solid #bbb; } .APB1 { background-color:#f9f9f9; color:#000; font-size:10px; text-align:center; text-decoration:underline; font-family:Arial, Times, serif; padding-top:2px; } .APB2 { background-color:#f9f9f9; color:#000; font-size:10px; text-align:center; font-family:Arial, Times, serif; } .APB3 { background-color:#f9f9f9; color:#384c7f; font-size:10px; text-align:center; font-family:Arial, Times, serif; } .APB45 { background-color:#f9f9f9; text-align:center; padding-bottom:2px; } .APB4 { background-color:#0066cc; color:#cccccc; font-size:10px; text-align:right; font-family:Arial, Times, serif; width:100px; height:10px; border:solid 1px #fff; } .APB5 { background-color:#ccc; color:#ff0045; font-size:10px; text-align:center; font-family:Arial, Times, serif; height:10px; float:right; }