MySQL和SQLite根据生日算年龄

MySQL:

1、select (date_format(from_days((to_days(now()) - to_days(birthday))),'%Y') + 0) AS age from table.

2、select timestampdiff(YEAR,birthday,curdate()) AS age from table

 

SQLite:

1、SELECT (strftime('%Y', 'now') - strftime('%Y', birthday)) - (strftime('%m-%d', 'now') < strftime('%m-%d', birthday)) from customer;

2、select cast(strftime('%Y.%m%d', 'now') - strftime('%Y.%m%d', birthday) as int) from customer;

posted @ 2014-03-15 11:09  半瓶子水  阅读(1122)  评论(0编辑  收藏  举报