我的数据库具有年份和月份列
year month createdate
1 2 2017-04-12 10:36:25
我想计算从创建日期的年月到现在(当前年月)的经验
答案 0 :(得分:1)
您可以使用TIMESTAMPDIFF函数。
SELECT
TIMESTAMPDIFF(YEAR, created_date, now()) as year,
TIMESTAMPDIFF(MONTH, created_date, now()) - TIMESTAMPDIFF(YEAR, created_date, now()) * 12 as month
FROM your_table;