Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在使用以下 Select 语句来获取用户的生日和其他信息。我想看看我是否可以在返回的数据中将日期转换为年龄 - 而不是在 PHP 中转换它。
数据库中的日期格式为:1979-04-26
SELECT profile_username,profile_gender,profile_birthdate FROM loginTable WHERE id=1000;
当前回报就像
Adam,Male,1979-04-26
我能回来吗:
Adam,Male,34
SELECT profile_username,profile_gender, DATE_FORMAT(NOW(), '%Y') - DATE_FORMAT(profile_birthdate, '%Y') - (DATE_FORMAT(NOW(), '00-%m-%d') < DATE_FORMAT(profile_birthdate, '00-%m-%d')) AS age FROM loginTable WHERE id=1000;
样品小提琴