Home  >  Article  >  Backend Development  >  Share the php code of Beibei's growth progress_PHP tutorial

Share the php code of Beibei's growth progress_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:16:04956browse

The main function is to show how old Beibei is now based on Beibei's date of birth, and to display Beibei's growth in real time.
Subtract the date of birth from the current time, but can display the age, months, and days.
There is something wrong with the day algorithm, as it does not take into account the big and small months and February.

Copy code The code is as follows:

function getDays() {
putenv("TZ=Asia/Chongqing") ;
$by = 2006;
$bm = 7;
$bd = 7;
$rday="";

$today = getdate();
$by = $today[year] - $by;
$bm = $today[mon] - $bm;
$bd = $today[mday] - $bd;
if ($bd < ; 0) {
$bd = 30 + $bd;
$bm--;
}
if ($bm < 0) {
$bm = 12 + $bm;
$by--;
}
#print $by."-".$bm."-".$bd;
if ($by > 0) {
$ rday = $by . "year";
}
if ($bm == 0&&$bd == 0){
$rday .="birthday";
}else{
if ($bm == 0){
$rday.="zero".$bd."day";
}elseif ($bd == 0){
$rday.=$bm. "month";
}else{
$rday.=$bm."month".$bd."day";
}
}
return $rday;
}

When using it, just copy the code
The code is as follows:

< ?php echo getDays();?>

That’s it.
Leave it blank and then improve the following and write a js version.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/325998.htmlTechArticleThe main function is to show how old Beibei is now based on Beibei's date of birth, and to display Beibei's growth in real time. Subtract the date of birth from the current time, but you can show how old you are...
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