to_date to_timestamp postgresql database and converted to time format string

Database: the string is converted to time format

Difference between the two:

        to_data converted into ordinary time format
        to_timestamp can be converted into timestamp format
error scenarios: Date Size comparison on the same day, it is very easy to make mistakes

For example:
        SELECT CURRENT_TIMESTAMP from pub_employee
        results are as follows:
        
    SELECT CURRENT_TIMESTAMP <= TO_DATE ( '2018-03-12 18:47:35', 'the MM-dd-YYYY HH24: mi The: SS') In Flag from pub_employee
    statement 2018-03 -12 18:47:35 current_timestamp than the current time is two hours
    but the results are as follows:

The result is false
because: select to_date ( '2018-03-12 18:47:35' , 'yyyy-MM-dd hh24: mi: ss') from pub_employee
results are as follows: not stamp


Correct wording
select current_timestamp <= to_timestamp ( '2018-03-12 18:47:35', 'yyyy-MM-dd hh24: mi: ss') flag from pub_employee
Results:
is true
because: select to_timestamp (' 2018- 03-12 18:47:35 ',' yyyy-MM -dd hh24: mi: ss') from pub_employee

    
============================================================
to_date:

One way: right
select to_date ( '2018-03-08', ' yyyy-MM-dd') from pub_employee
Second way:
SELECT TO_DATE ( '2018-03-08 18:55:33', 'the MM-dd-YYYY ') from pub_employee
third approach:
SELECT TO_DATE (' 2018-03-08 18:55:33 ',' the MM-dd-YYYY HH24: mi The: SS ') from pub_employee

Use to_date are returned the following results:

 


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

 

---------------------
作者:大bug
来源:CSDN
原文:https://blog.csdn.net/sky_limitless/article/details/79527665
版权声明:本文为博主原创文章,转载请附上博文链接!

Guess you like

Origin www.cnblogs.com/telwanggs/p/11056500.html