如何轻松确定生日的年龄? (php) [英] How do I easily determine the age from an birthday? (php)
本文介绍了如何轻松确定生日的年龄? (php)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:
计算从日期起的年份
这是我有的。
$ qPersoonsgegevens =SELECT * FROM alg_persoonsgegevens WHERE
alg_persoonsgegevens_leerling_ID = $ leerling_id;
$ rPersoonsgegevens = mysql_query($ qPersoonsgegevens);
$ aPersoonsgegevens = mysql_fetch_assoc($ rPersoonsgegevens);
$ timeBirthdate = mktime($ aPersoonsgegevens ['alg_persoonsgegevens_geboortedatum']);
不幸的是,我不知道如何从这一点开始获得年龄。 >
非常感谢任何帮助。
Matthy
解决方案
之前已经询问过。尝试这样:
函数getAge($ then){
$ then = date('Ymd',strtotime($ then));
$ diff = date('Ymd') - $ then
return substr($ diff,0,-4);
}
调用如下:
$ age = getAge($ aPersoonsgegevens ['alg_persoonsgegevens_geboortedatum']);
Possible Duplicate:
Calculate years from date
Hi,
I have a table with a field representing the birthday. How do I find the age of the person from that date?
This is what I have.
$qPersoonsgegevens = "SELECT * FROM alg_persoonsgegevens WHERE
alg_persoonsgegevens_leerling_ID = $leerling_id";
$rPersoonsgegevens = mysql_query($qPersoonsgegevens);
$aPersoonsgegevens = mysql_fetch_assoc( $rPersoonsgegevens );
$timeBirthdate = mktime($aPersoonsgegevens['alg_persoonsgegevens_geboortedatum']);
Unfortunately, I don't know how to proceed from that point to get the age.
Any help is much appreciated.
Matthy
解决方案
This has been asked before. Try this:
function getAge($then) {
$then = date('Ymd', strtotime($then));
$diff = date('Ymd') - $then;
return substr($diff, 0, -4);
}
Call it like so:
$age = getAge($aPersoonsgegevens['alg_persoonsgegevens_geboortedatum']);
这篇关于如何轻松确定生日的年龄? (php)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文