简体   繁体   中英

Comparing Date/time on Oracle

Currently on my oracle table, I have the following if condition on my procedure

if TO_CHAR(updatetime, 'DD-MON-YYYY HH:MI:SS') != '01-JAN-1900 00:00:01' then

Suppose the value updatetime from oracle table is "01-JAN-1900 12:00:01 AM" , will my if condition be true or false?

The reason I'm asking is because I am unsure about the format TO_CHAR converts to. Value on the table is in a 12-Hr clock format, while the condition compares with a 24-hr format.

This is my first week working with oracle sql..

Thanks !

What @Tony Andrews said, but you probably want to make your to_char convert to 24 hour clock if you're comparing it to a string containing 24 hour clock value. Change HH to HH24 like this:

if TO_CHAR(updatetime, 'DD-MON-YYYY HH24:MI:SS') != '01-JAN-1900 00:00:01' then 

Oracle DATE columns do not hold the date as a formatted string, it is held (internally) as 7 numeric values: century, year, month, day, hour, minute, second. So it doesn't matter what format you use in your TO_CHAR.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM