Calculate the age using data from my database

前端 未结 3 1523
执念已碎
执念已碎 2021-01-24 22:41

This is the code I\'m currently using, but it\'s not working. Geboortedatum means day of birth in Dutch.

mysql_connect(\'xxx\', \'xxx\', \'xxx\');

mysql_select_         


        
3条回答
  •  青春惊慌失措
    2021-01-24 23:30

    No need for PHP calculation. MySQL might do it by itself (with help of TIMESTAMPDIFF()):

    SELECT TIMESTAMPDIFF(YEAR, `Geboortedatum`, NOW()) as `age` FROM `Personen`;
    

    If you store your date in format, that differs form MySQL Date format (i.e. not in YYYY-mm-dd format), then you may try to format it with STR_TO_DATE() function.

提交回复
热议问题