1,现在的时间,日期和时刻
select now(),current_date(),current_time()
2,现在的年份 select year(now()),也可以把year改为month,day,hour,minute,second
所有这些都是返回整数值,
如果要返回字符串,加个name,比如select monthname(now())。dayname也可以
3,如果要把数据录入其他DBMS最好使用extra 函数
比如select extract(day from now())
练习:假设我们要查询2019年的订单,今年是2019年,之前我们是这么写的,但是不建议,因为到了2020年,这个查询就会变成2019-2020年的订单。
答案:这题目前做不了了,返回的值是空的,因为今年已经是2023年了。
select *
from orders
where year(order_date)=year(now())