mysql常用日期和时间函数

好久没写博客了,QAQ

1、获取当前时间 now() sysdate()

select now()
2018-08-09 18:30:15
select sysdate()
2018-08-09 18:31:39

以上两个的区别是now()是在sql语句执行时就获取到了时间,也就是你点击运行时的时间
而sysdate()是获取执行到sysdate()的时间

select now(),sleep(3),now();
2018-08-09 18:34:18 \ 2018-08-09 18:34:18
select sysdate(),sleep(3),sysdate() ;
2018-08-09 18:36:04 \ 2018-08-09 18:36:01

sleep(int second)指延时多少秒

2、获取当前时间戳函数

select current_timestamp
2018-08-09 18:40:01
select current_timestamp()
2018-08-09 18:40:01

3、获取当前时分秒

select current_time
18:38:49

4、Unix 时间戳、日期转换函数

unix_timestamp(),
unix_timestamp(date),
from_unixtime(unix_timestamp),
from_unixtime(unix_timestamp,format)

select unix_timestamp()
1533811373
select unix_timestamp(“2018-8-8”)
1533657600
select from_unixtime(1533657600,”%Y %D %M %h:%i:%s %x”)
2018 8th August 12:00:00 2018

5、date_add() date_sub() datediff()函数

select datediff(“2015-11-16”,now())
-997
select timestampdiff(day,”2015-11-16”,now())
997

具体可参考http://www.cnblogs.com/ggjucheng/p/3352280.html,感谢!!!!

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值