1、获取指定时间
函数:date_format()
转换
# 获取前一天时间的最大值 select date_format(current_date()-1, '%y-%m-%d 23:59:59') # 定义时间值,时间为当前时间整点 select @front_time := (select concat(current_date(),' ', date_format(now(),'%h'),':00:00')); # 定义时间值,时间为前一小时 select @front_time := (select concat(current_date(),' ', date_format(now(),'%h')-1,':00:00'));
效果:
2、获取当前时间:年-月-日 时:分:秒
2.1、函数 now() :
# 获取格式为当前时间:年-月-日 时:分:秒 select now()
效果:
2.2、函数 sysdate()
# 获取格式为当前时间:年-月-日 时:分:秒 select sysdate()
效果:
2.3 、函数 current_timestamp()
# 获取格式为当前时间:年-月-日 时:分:秒 select current_timestamp()
效果:
2.4、函数:localtime()
select localtime();
效果:
2.5、函数:localtimestamp()
select localtimestamp();
效果:
3、获取当前时间:年-月-日
3.1、函数:current_date()
select current_date();
效果:
3.2、函数:curdate()
select curdate();
效果:
3.3、函数:utc_date()
#。**因为我国位于东八时区,所以本地时间 = utc 时间 + 8 小时** select utc_date(); # utc_date() 年月日 # utc_time() 时分秒 # utc_timestamp() 年月日 时分秒
效果:
4、返回本月最后一天时间
函数:last_day()
select last_day(now());
效果:
到此这篇关于mysql 获取时间方式的文章就介绍到这了,更多相关mysql 获取时间内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!
声明:如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。