date_format函数在pg数据库怎么替换(pg数据库格式化日期)


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

 

 仔细看上面的例子,因为格式的不同输出的结果是不一样的,特别需要注意。

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM