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.

Age Progression Bar
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<?
################################################################################
#AGEPROGRESSION BAR          REV. 4.0                          M.Tunstall 2004 #
#------------------------------------------------------------------------------#
#----------------------http://www.deltanova.co.uk------------------------------#
#------------------------------------------------------------------------------#
#The idea behind this project is to create a visual indicator to show how long #
#you have left before you get a year older.                                    #
################################################################################
#Revision History                                                              #
#------------------------------------------------------------------------------#
#REV 4.0 Modified the age calculation as age was reported incorrectly when     #
#            birthmonth and current month were the same (2/11/2004)                            #
#REV 3.0 Modified the script to output XHTML 1.1 compliant code, now uses      #
#        external stylesheet                                                       #
#REV 2.0 Rewrote days calculation, fixed bugs, modified output code. (2002)    #
#REV 1.0 Basically Working with some bugs.                                     #
################################################################################
#USE:                                                                          #
#           include("APB.php");  // Put where you want on the page                 #
# // Place the foloowing in the pages header tags to include the stylesheet    #
# <link rel="stylesheet" type="text/css" media="screen" href="APB_Style.css" />#
################################################################################
//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 <div class="APB3">';
$Person = $Name;
$EndGreeting = '</div>';
}
else
{
$DTG = "$DaysToGo";
$StartGreeting ="";
$Person ="";
$EndGreeting ="";
}
?>
<?
##################################################################################
# This section of code is for the layout of the output                           #
##################################################################################
# If you plan on displaying the output on a single page, you will need to        #
# uncomment the header and footer code below.                                    #
# If you are including the code in a page, the headers must not be included.     #
# Including the headers will cause an invalid page layout. When including you    #
# will still need to include the stylesheet link in the header tags of the page  #
# you are putting it on. Below is the stylesheet link                            #
# <link rel="stylesheet" type="text/css" media="screen" href="APB_Style.css" />  #
##################################################################################
#<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
#<html xmlns="http://www.w3.org/1999/xhtml">
#<head>
#<title>Age Progession Bar</title>
#<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
#<link rel="stylesheet" type="text/css" media="screen" href="APB_Style.css" />
#</head>
#<body>
?>
<div class="APB">
<div class="APB1">Age Progression Bar</div>
<div class="APB2"> Current Age:<div class="APB3"><? echo "$age"; ?></div></div>
<div class="APB2" >Days till <? echo "$nextage";?>:<div class="APB3"><? echo "$DTG"; ?></div></div>
<div class="APB2" >Trasnsition Progress:<div class="APB3"><? echo "$prcnt"; ?> %</div></div>
<div class="APB45"><div class="APB4"><div class="APB5" style="width:<? echo "$Width2"; ?>px"></div></div></div>
<div class="APB2" ><? echo "$StartGreeting $Person $EndGreeting"; ?></div>
<? #echo "$nowdate $birthday $age2"; ?>
</div>
<p/>
<?
#</body>
#</html>
?>
<?
################################################################################
# Thanks to neotek who gave me the code for his "AgeBar" script which                  #
# inspired me.                                                                 #
# http://neotek.m0use.net                                                      #
################################################################################
?>
Age Progression Bar Stylesheet
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
.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;
}
Previous: Birthday   Next: Phat Sound