当前时间
current_timestamp()
例如:2021-03-25 09:41:54.965
timestamp->秒数(unix日期从1970-01-01 00:00:00’至今的秒数)
unix_timestamp()
unix_timestamp(current_timestamp())
例如:1616636514
字符串转秒数
unix_timestamp('2021-03-25 09:41:54.965'),字符串默认为:yyyy-MM-dd HH:mm:ss
unix_timestamp('2018/06/29 09', 'yyyy/MM/dd HH')
秒数->字符串
from_unixtime(1616636514,'yyyy/MM/dd')
例如:2021/03/25
日期->字符串
from_unixtime(unix_timestamp(current_timestamp()),'yyyy/MM')
date_format(current_timestamp(),'yyyy-MM-dd')
字符串->日期???
from_unixtime(unix_timestamp('${BizDate}' ,'yyyyMMdd'))
字符串->日期
date_format('20221010' ,'yyyyMMdd')
日期时间->天,=trunc(sysdate)
to_date(current_timestamp())
日期时间->月
select trunc(current_timestamp(),'MM')
上个月最后一天
date_add(cast(trunc(current_timestamp(),'MM') as timestamp),-1)
日期增加
date_add(current_timestamp(),-1)
日期相差,计算时候忽略时分秒,只看跨越的天数。例如2022-10-10 00:01:01 - 2022-10-09 23:59:59,结果是1
datediff(current_timestamp(),cast(to_date('2022-10-01') as timestamp) )
昨天yyyyMMdd
date_format(date_add(current_timestamp(),-1),'yyyyMMdd')