时间戳

  1. select unix_timestamp('20201231','yyyyMMdd')
  2. > 1609372800
  3. select unix_timestamp('2020-12-31','yyyy-MM-dd')
  4. > 1609372800

日期格式转换

  1. select from_unixtime(1609372800,'yyyy-MM-dd')
  2. > 2020-12-31
  3. select from_unixtime(1609372800,'yyyyMMdd')
  4. > 20201231

注意: 该函数 FUNC(bigint, string) 要求第一个参数必须为整型,若为字符串则会报错! 例如:select from_unixtime(‘1609372800’,’yyyyMMdd’); —> [Error 10014]

日期差

  1. select datediff('2020-12-31','2020-01-01'); -- 两个输入参数必须为'日期格式'
  2. > 365