|
1 | 1 | <?php |
2 | 2 |
|
3 | | -echo "hello world!"; |
| 3 | +if(isset($_POST['sub'])) |
| 4 | + |
| 5 | +{ |
| 6 | + |
| 7 | +$mm=$_POST['mm']; |
| 8 | + |
| 9 | +$dd=$_POST['dd']; |
| 10 | + |
| 11 | +$yy=$_POST['yy']; |
| 12 | + |
| 13 | +$dob=$mm."/".$dd."/".$yy; |
| 14 | + |
| 15 | +$arr=explode('/',$dob); |
| 16 | + |
| 17 | +//$dateTs=date_default_timezone_set($dob); |
| 18 | +$dateTs=strtotime($dob); |
| 19 | + |
| 20 | +$now=strtotime('today'); |
| 21 | + |
| 22 | +if(sizeof($arr)!=3) die('ERROR:please entera valid date'); |
| 23 | + |
| 24 | +if(!checkdate($arr[0],$arr[1],$arr[2])) die('PLEASE: enter a valid dob'); |
| 25 | + |
| 26 | +if($dateTs>=$now) die('ENTER a dob earlier than today'); |
| 27 | + |
| 28 | +$ageDays=floor(($now-$dateTs)/86400); |
| 29 | + |
| 30 | +$ageYears=floor($ageDays/365); |
| 31 | + |
| 32 | +$ageMonths=floor(($ageDays-($ageYears*365))/30); |
| 33 | + |
| 34 | +echo "<font color='red' size='10'> You are aprox $ageYears years and $ageMonths months old. </font>"; |
| 35 | + |
| 36 | +} |
| 37 | + |
| 38 | +?> |
| 39 | + |
| 40 | +<form method="post"><center> |
| 41 | + |
| 42 | +choose your DOB |
| 43 | + |
| 44 | + <select name="yy"> |
| 45 | + <option value="">Year</option> |
| 46 | + <?php |
| 47 | + for($i=1900;$i<=2014;$i++) |
| 48 | + { |
| 49 | + echo "<option value='$i'>$i</option>"; |
| 50 | + } |
| 51 | + ?> |
| 52 | + </select> |
| 53 | + |
| 54 | + |
| 55 | + <select name="mm"> |
| 56 | + <option value="">Month</option> |
| 57 | + <?php |
| 58 | + for($i=1;$i<=12;$i++) |
| 59 | + { |
| 60 | + echo "<option value='$i'>$i</option>"; |
| 61 | + } |
| 62 | + ?> |
| 63 | + </select> |
| 64 | + |
| 65 | + |
| 66 | + <select name="dd"> |
| 67 | + <option value="">Date</option> |
| 68 | + <?php |
| 69 | + for($i=1;$i<=31;$i++) |
| 70 | + { |
| 71 | + echo "<option value='$i'>$i</option>"; |
| 72 | + } |
| 73 | + |
| 74 | + ?> |
| 75 | + </select> |
| 76 | + |
| 77 | +<input type="submit" name="sub" value="check it"/> |
| 78 | + |
| 79 | + </center> |
| 80 | + |
| 81 | + </form> |
| 82 | + |
| 83 | + |
| 84 | +Output You are aprox 26 years and 4 months old choose your DOB |
| 85 | +Create an age Calculator(Enter your DOB in text box) |
| 86 | +<?php |
| 87 | + |
| 88 | +error_reporting(1); |
| 89 | + |
| 90 | +$day=0; |
| 91 | + |
| 92 | +$yr=0; |
| 93 | + |
| 94 | +$mon=0; |
| 95 | + |
| 96 | +if(isset($_POST['b1'])) |
| 97 | + |
| 98 | +{ |
| 99 | + |
| 100 | +$d1=$_POST['t1']; |
| 101 | + |
| 102 | +$d2=$_POST['t2']; |
| 103 | + |
| 104 | +$arr=explode("/",$d1); |
| 105 | + |
| 106 | +$brr=explode("/",$d2); |
| 107 | + |
| 108 | +if($arr[0]<$brr[0]) |
| 109 | + |
| 110 | +{ |
| 111 | + |
| 112 | +$arr[0]+=30; |
| 113 | + |
| 114 | +$arr[1]-=1; |
| 115 | + |
| 116 | +} |
| 117 | + |
| 118 | +$day=$arr[0]-$brr[0]; |
| 119 | + |
| 120 | +if($arr[1]<$brr[1]) |
| 121 | + |
| 122 | +{ |
| 123 | + |
| 124 | +$m1+=12; |
| 125 | + |
| 126 | +$arr[2]-=1; |
| 127 | + |
| 128 | +} |
| 129 | + |
| 130 | +$mon=$arr[1]-$brr[1]; |
| 131 | + |
| 132 | +$yr=$arr[2]-$brr[2]; |
| 133 | + |
| 134 | +} |
| 135 | + |
| 136 | +?> |
| 137 | + |
| 138 | +<form method="post"> |
| 139 | + |
| 140 | +<table border="2"> |
| 141 | + |
| 142 | +<tr> |
| 143 | + |
| 144 | +<td align="center" colspan="2"><font color="orange"><h2><b>Age Calculator</b></h2></font></td> |
| 145 | + |
| 146 | +</td> |
| 147 | + |
| 148 | +<tr> |
| 149 | + |
| 150 | +<td align="center"><b>enter current date:</b></td> |
| 151 | +<td align="center"><input type="text" name="t1" autofocus></td> |
| 152 | + |
| 153 | +</tr> |
| 154 | + |
| 155 | +<tr> |
| 156 | + |
| 157 | +<td align="center"><b>enter your DOB:</b></td> |
| 158 | + |
| 159 | +<td align="center"><input type="text" name="t2"></td> |
| 160 | + |
| 161 | +</tr> |
| 162 | + |
| 163 | +<tr> |
| 164 | + |
| 165 | +<td align="center" colspan="2"><input type="submit" name="b1" value="calculate"></td> |
| 166 | + |
| 167 | +</tr> |
| 168 | + |
| 169 | +<tr> |
| 170 | + |
| 171 | +<td align="center"><b>Your Age is:</b></td> |
| 172 | + |
| 173 | +<td align="center"> |
| 174 | + |
| 175 | +<?php |
| 176 | + |
| 177 | +error_reporting(1); |
| 178 | + |
| 179 | +echo '<font color="blue" size="5">'; |
| 180 | + |
| 181 | +echo $yr.' years '.$mon.' months '.$day.' days '; |
| 182 | + |
| 183 | +echo '</font>'; |
| 184 | + |
| 185 | +?> |
| 186 | + |
| 187 | +</td> |
| 188 | + |
| 189 | +</tr> |
| 190 | + |
| 191 | +</table> |
| 192 | + |
| 193 | +</form> |
0 commit comments