Search code examples
sqloracle-databasesql-timestamp

TO_TIMESTAMP Compare


SELECT  lastmoddate
        , to_timestamp(lastmoddate,'DD-MON-YYYY HH:MI:SS:FF AM')
        , cast(current_timestamp - interval '60' day as TIMESTAMP)
FROM table 
WHERE primaryKeyColumn = 12141969;

returns:

enter image description here

SELECT problemid
       , lastmoddate
       , to_timestamp(lastmoddate,'DD-MON-YYYY HH:MI:SS:FF AM')
       , cast((current_timestamp - 60) as TIMESTAMP)
FROM table 
WHERE primaryKeyColumn = 12141969
and to_timestamp(lastmoddate,'DD-MON-YYYY HH:MI:SS:FF AM') < cast((current_timestamp - 60)  as TIMESTAMP);

returns:

enter image description here

I don't understand how is 25th Aug less than 19th Aug.


Solution

  • Thanks to everyone, Especially Gordon, Gary. You guys nailed it. When I ran to_CHAR(lastmoddate,'DD-MON-YYYY HH24:MI') I noticed it had 0018 stored in Year. This solved my problem