- 统计2个时间差:SELECT datediff( '2019/11/19 00:00','2019/11/23 00:00' );
2.定义时间变量:
SET @dtnow = now( ); #当前时间
SET @dt1 = ( CAST( SYSDATE( ) AS DATE ) - INTERVAL 30 DAY );#30天前
SET @dt2 = ( CAST( SYSDATE( ) AS DATE ) - INTERVAL 0 DAY );#截止今天
SET @daynum = DATEDIFF( @dt2, @dt1 );#2时间差的天数
UNIX_TIMESTAMP( @dt1 );# 取时间戳
select UNIX_TIMESTAMP( now( ) ); #将格式化时间转为时间戳
select FROM_UNIXTIME(unix_timestamp(now()),'%Y-%m-%d %H:%i:%s');将时间戳转为格式化时间