In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-12 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly shows you "how to calculate age by birthday in Mysql". The content is simple and easy to understand, and the organization is clear. I hope it can help you solve your doubts. Let Xiaobian lead you to study and learn this article "how to calculate age by birthday in Mysql".
method one
SELECT DATE_FORMAT(FROM_DAYS(TO_DAYS(NOW())-TO_DAYS(birthday)), '%Y')+0 AS age
Method 1, the author also points out the flaw, that is, when the date is a future date, the result is 0, not negative; here five functions and two operators are used.
methodology II
SELECT DATE_FORMAT(NOW(), '%Y') - DATE_FORMAT(birthday, '%Y') - (DATE_FORMAT(NOW(), '00-%m-%d') < DATE_FORMAT(birthday, '00-%m-%d')) AS age
Method 2 solves the problem of method 1 being negative, but looks more complex; six functions and three operators are used.
After reading this post, I was dizzy, how can it be so complicated, before using SQL Server is very simple can be. I believe there must be a simple and efficient way. A modified method based on the above method was quickly found.
Improved methods 1 and 2
SELECT year( from_days( datediff( now( ), birthdate)));SELECT YEAR(CURDATE())-YEAR(birthday)-(RIGHT(CURDATE(),5)
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.