剛開始用mysql,需要用出生日期計算年齡,而且需要查詢符合這個年齡的使用者資訊。網路上介紹了不少顯示年齡的方法,但是要使用where語句查詢時,就失效了。在網路上找到了一位大神的回答,親測有用。
題目:查詢年齡為33的使用者資訊
select customers.cusname,customers.***,timestampdiff(year,customers.birthday,curdate())as 'age'
from customers
where timestampdiff(year,customers.birthday,curdate())='33'
注:1、customers是表名
2、customers.birthday是鍊錶儲存出生日期的屬性,'age'是別名,年齡。
mysql根據出生日期計算年齡
select date format from days to days now to days birthday y 0 as age方法一,作者也說出了缺陷,就是當日期為未來日期時結果為0,而不是負數 這裡使用了5個函式和兩個運算子。select date format now y date f...
通過出生日期計算年齡
關於通過出生日期計算年齡的問題,通過baidu搜尋得到很多 貼了以下函式 function calcage datempdateofbirth as variant as integer calcage int datediff y datempdateofbirth,date 365.25 end...
SQL Server 根據出生日期計算年齡
getdate 函式用於返回當前的日期和時間 datediff 函式返回兩個日期之間的時間。語法 datediff datepart,startdate,enddate startdate 和 enddate 引數是合法的日期表示式。datepart 引數可以是下列的值 datepart縮寫年 yy...