date_format 在pg數據庫中用to_date 可以實現想要的功能,但是注意兩個函數是有區別的,不是一樣的,只是要實現的功能來說是存在相同的。關於to_date格式下面有記錄:
to_date 轉換為 普通的時間格式
to_timestamp 轉換可為 時間戳格式
這個兩個返回的時間格式是不一樣的,
============================================================
to_date:
方式一:正確
select to_date('2018-03-08','yyyy-MM-dd') from pub_employee
方式二:
select to_date('2018-03-08 18:55:33','yyyy-MM-dd') from pub_employee
方式三:
select to_date('2018-03-08 18:55:33','yyyy-MM-dd hh24:mi:ss') from pub_employee
使用to_date 返回的都是以下結果:
to_timestamp:
方式一:
select to_timestamp('2018-03-08','yyyy-MM-dd') from pub_employee
方式二:
select to_timestamp('2018-03-08 18:55:33','yyyy-MM-dd') from pub_employee
方式一和二都是以下格式,雖然都是時間戳,但是后面一截是0
方式三:正確
select to_timestamp('2018-03-08 18:55:33','yyyy-MM-dd hh24:mi:ss') from pub_employee
仔細看上面的例子,因為格式的不同輸出的結果是不一樣的,特別需要注意。