赞
踩
1,获取当前时间
select now();//2019-03-26 11:11:55
select curdate();//2019-03-26
select curtime();//11:11:55
select year(curdate());//2019
select month(curdate());//3
select day(curdate());//26
select hour(now());//11
select minute(now());//11
select second(now());//55
select microsecond(now());//0
2,获取上月时间
select date_sub(now(),interval 1 month);//2019-02-26 11:11:55
select date_sub(curdate(),interval 1 month);//2019-02-26
select date_add(curdate(),interval -1 month);//2019-02-26
3,获取下月时间
select date_sub(now(),interval -1 month);//2019-04-26 11:11:55
select date_add(curdate(),interval 1 month);//2019-04-26
4,获取最后一天
select last_day(curdate());//2019-03-31
5,获取第一天
select date_add(curdate(),interval -day(curdate())+1 day)//当月2019-03-01
select date_add(curdate()-day(curdate())+1,interval 1 month)//下月2019-04-01
6,获取当月天数(先获得最后一天,再获得天数)
select day(last_day(curdate()));
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。