SQL中year函数用法

year(date())-year和year(now())-year有什么区别吗?

date和year都是获取当前系统时间的函数
其中date函数仅获取年月日,而now函数获取年月日、时分秒,如果是在只求年月日的情况下,两者是没啥区别的
year()函数是返回一个指定日期的年份值
因此year(date())=year(now())等价
因此year(date())-year和year(now())-year无区别

望采纳!!!
主要是date()和now()的区别
以mysql为例
now() Returns the current date and time as a value in 'YYYY-MM-DD hh:mm:ss'
now 和 sysdate函数,now取的是函数执行时的开始事件,而sysdate取的是执行事件。
date() 貌似 Extracts the date part of the date or datetime expression expr. Returns NULL if expr is NULL.;需要有入参才行

mysql中SELECT year(date())会报错
SELECT year(now()) 提取的是年份