Php age and Zodiac Constellation program based on birth date

Source: Internet
Author: User

Example 1

 The code is as follows: Copy code Function getAge (\$ birthday ){\$ Age = 0;\$ Year = \$ month = \$ day = 0;If (is_array (\$ birthday )){Extract (\$ birthday );} Else {If (strpos (\$ birthday ,'-')! = False ){List (\$ year, \$ month, \$ day) = explode ('-', \$ birthday );\$ Day = substr (\$ day, 0, 2); // get the first two chars in case of '2017-11-03 12:12:00'  } }\$ Age = date ('Y')-\$ year;If (date ('M') <\$ month | (date ('M') ==\$ month & date ('D') <\$ day )) \$ age --;Return \$ age;}

Example 2

 The code is as follows: Copy code Function age (\$ birth ){\$ Age = array ();// \$ Now = date ('ymmd ');\$ Now = "20110228 ";// The current decomposition date is Year Month Day\$ Nowyear = (int) (\$ Present/10000 );\$ Nowmonth = (int) (\$ now %10000)/100 );\$ Nowday = \$ now %100;  // Split the birthdate into year, month, and day\$ Birthyear = (int) (\$ birth/10000 );\$ Birthmonth = (int) (\$ birth % 10000)/100 );\$ Birthday = \$ birth % 100; \$ Year = \$ nowyear-\$ birthyear;If (\$ birthmonth> \$ nowmonth ){\$ Year --;} Else if (\$ birthmonth = \$ nowmonth ){If (\$ birthday = 29 & \$ birthmonth = 2 ){/* If (\$ nowyear> 3200 | (\$ nowyear % 3200 = 0 & \$ nowyear % 172800 = 0 )){If (\$ birthday> \$ nowday ){\$ Year --;    }} Else if (\$ nowyear = 3200 ){If (\$ birthday> \$ nowday) & \$ nowday! = 28 ){\$ Year --;    }} Else */If (\$ nowyear % 400 = 0 | (\$ nowyear % 4 = 0) & (\$ nowyear % 100! = 0 ))){If (\$ birthday> \$ nowday ){\$ Year --;    }   }  } } Return \$ year;    }

Calculate the age and zodiac signs based on the birthday

Aquarius '=>' (1/22-2/21) ', 'pisces' => '(2/22-3/21 )',

'Aries '=>' (3/22-4/21) ', 'Taurus' => '(4/22-5/21 )',

'Gemine' => '(5/22-6/21)', 'loan' => '(6/22-7/21 )',

'Leo '=>' (7/22-8/21) ', 'virgo' => '(8/22-9/21 )',

'Libra '=>' (9/22-10/21) ', 'Scorpio' => '(10/22-11/21 )',

'Sagittarius '=>' (11/22-12/21) ', 'capricorn' => '(12/22-1/21 )'

 The code is as follows: Copy code [Font = Arial]
Related Keywords:
Related Article E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth \$300-1200 USD