Differences

This shows you the differences between two versions of the page.

Link to this comparison view

computers:php_calculate_age [2015/03/24 05:42] (current)
Line 1: Line 1:
 +====== Calculate Age in Years ======
 +Calculate anyone'​s age without worrying about the Unix Epoch
  
 +====== Resources ======
 +
 +
 +
 +
 +
 +====== Server Side Code ======
 +
 +
 +
 +===== PHP function calculate_age() =====
 +[[http://​www.zend.com/​code/​codex.php?​id=1206&​single=1]] \\
 +Type:  code fragment\\
 +Added by: [[http://​www.zend.com/​code/​search_code_author.php?​author=mattnorniron |mattnorniron]]\\
 +Entered: 02/​06/​2003\\
 +Last modified: 06/​12/​2002\\
 +
 +<code php>
 +<?
 +
 +/* I wrote this snippet to combat the limitations of the mktime function due to the beginning of the Unix Epoch. */
 +
 +function calculate_age($birth_day,​ $birth_month,​ $birth_year) { 
 +
 +     ​$datestamp = date("​d.m.Y",​ mktime());
 +     ​$t_arr = explode("​."​ , $datestamp);​
 +     
 +     ​$current_day = $t_arr[0];
 +     ​$current_month = $t_arr[1];
 +     ​$current_year = $t_arr[2];
 +     
 +     ​$year_dif = $current_year - $birth_year;​
 +     
 +     ​if(($birth_month > $current_month) || ($birth_month == $current_month && $current_day < $birth_day))
 +         $age = $year_dif - 1;
 +     else
 +         $age = $year_dif;
 +
 +     ​return $age;
 +
 +
 +
 +
 +</​code>​
 +
 +
 +===== Code 2 =====
 +Description,​ change title as needed
 +
 +<code php>
 +
 +</​code>​
 +
 +
 +
 +====== Client Side Code ======
 +Client side code is inherently insecure and error prone. ​ It should be used to reduce load on server, and input verified ​ by server. ​ Please include server verification code also in this section.
 +
 +===== Code Title =====
 +Description,​ change title as needed
 +
 +<code javascript>​
 +
 +</​code>​
 +
 +====== Candidate Code Suggestions ======
 +Add your suggestions and links here.