qq管家官方下载-winexec

timestampdiff
2023年4月3日发(作者:pc游戏手柄)

mysql时间戳参数_MySQL时间戳(Timestamp)函数

获得当前时间戳函数:current_timestamp,current_timestamp()

mysql>selectcurrent_timestamp,current_timestamp();

+---------------------+---------------------+

|current_timestamp|current_timestamp()|

+---------------------+---------------------+

|2008-08-0923:22:24|2008-08-0923:22:24|

+---------------------+---------------------+

(Unix时间戳、⽇期)转换函数:

unix_timestamp(),

unix_timestamp(date),

from_unixtime(unix_timestamp),

from_unixtime(unix_timestamp,format)

下⾯是⽰例:

selectunix_timestamp();--1218290027

selectunix_timestamp('2008-08-08');--1218124800

selectunix_timestamp('2008-08-0812:30:00');--1218169800

selectfrom_unixtime(1218290027);--'2008-08-0921:53:47'

selectfrom_unixtime(1218124800);--'2008-08-0800:00:00'

selectfrom_unixtime(1218169800);--'2008-08-0812:30:00'

selectfrom_unixtime(1218169800,'%Y%D%M%h:%i:%s%x');--'20088thAugust12:30:002008'

时间戳(timestamp)转换、增、减函数:

timestamp(date)--datetotimestamp

timestamp(dt,time)--dt+time

timestampadd(unit,interval,datetime_expr)--

timestampdiff(unit,datetime_expr1,datetime_expr2)--

请看⽰例部分:

selecttimestamp('2008-08-08');--2008-08-0800:00:00

selecttimestamp('2008-08-0808:00:00','01:01:01');--2008-08-0809:01:01

selecttimestamp('2008-08-0808:00:00','1001:01:01');--2008-08-1809:01:01

selecttimestampadd(day,1,'2008-08-0808:00:00');--2008-08-0908:00:00

selectdate_add('2008-08-0808:00:00',interval1day);--2008-08-0908:00:00

MySQLtimestampadd()函数类似于date_add()。

selecttimestampdiff(year,'2002-05-01','2001-01-01');---1

selecttimestampdiff(day,'2002-05-01','2001-01-01');---485

selecttimestampdiff(hour,'2008-08-0812:00:00','2008-08-0800:00:00');---12

selectdatediff('2008-08-0812:00:00','2008-08-0100:00:00');--7

MySQLtimestampdiff()函数就⽐datediff()功能强多了,datediff()只能计算两个⽇期(date)之间相差的天数

更多推荐

timestampdiff