Home  >  Article  >  Backend Development  >  Calculate age based on date of birth (taking into account leap years)

Calculate age based on date of birth (taking into account leap years)

WBOY
WBOYOriginal
2016-07-25 09:06:192151browse
Mainly considering the situation of leap years, if someone is born on 2.29, then if it is not a leap year, then 2.28 will be counted as one year old.                  
                                                                                                                                                                                                                                                                                                        OnFunction Age ($ BIRTH) {
$ Age = Array ();
// $ now = date ('ymd');
$ now = "20110228";
              $nowyear = (int) ($now / 10000);
                  $nowmonth = (int) (($now % 10000) / 100);              //Decompose the date of birth into Year, month and day
            $birthyear = (int) ($birth / 10000);
              $birthmonth = (int) (($birth % 10000) / 100);
  1.             $birthday =  $birth % 100;
  2.                                                $ Nowyear-$ BIRTHYEAR;
  3. If ($ BIRTHMONTH & GT; $ Nowmonth) {
  4. $ Year-;
  5. } Else If ($ BIRTHMONTH == $ Nowmonth) {
  6. b ($ Birthday == 29 & & $ BIRTHMONTH = 2) {
  7. / *                                                                             $year--;                                                                             $nowyear==3200){
  8.                                                                                                                                                                                                                                                                                                                                   (($nowyear%4==0)&&($nowyear%100!=0))){
  9.                                                                                                                                                                                         ;
  10.                                                                  return $year;
  11.                                                                                                               
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:Discuz template engineNext article:Discuz template engine