![]() | |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hi, I was wondering how I should convert a timestamp to compare it to '01-AUG-2006'. Is any of the following right? TO_CHAR(TRUNC(MYTIMESTAMP)) < '01-AUG-2006' TO_DATE(TRUNC(MYTIMESTAMP)) < '01-AUG-2006' TO_CHAR(MYTIMESTAMP,'DD-MON-YYYY') < '01-AUG-2006' If you could give a brief explaination of why I am getting a different result for each of the previous answer, i would really appreciate. |

#3
| |||
| |||
|
#4
| |||
| |||
|
|
Hi Martin, Thank you for your reply. I need to convert my timestamp to a string as i'd like to compare it to '01-AUG-2006'. I thought that TO_CHAR(MYTIMESTAMP,'DD-MON-YYYY') < '01-AUG-2006' would do it, but someone else from work told me to use TO_DATE(SUBSTR(TO_CHAR(MYTIMESTAMP), 1, 9), 'DD-MON-RRRR') '01-AUG-2006' but i'm sure if he's right or not. Could you explain it, please? Why would you want to compare the date as a string? |
|
TO_CHAR(MYTIMESTAMP,'DD-MON-YYYY') < '01-AUG-2006' This will compare strings, and is most likely not what you want! |
|
TO_DATE(SUBSTR(TO_CHAR(MYTIMESTAMP), 1, 9), 'DD-MON-RRRR') '01-AUG-2006' but i'm sure if he's right or not. Could you explain it, This does make even less sense to me ... |
#5
| |||
| |||
|
|
Faby wrote: Hi Martin, Thank you for your reply. I need to convert my timestamp to a string as i'd like to compare it to '01-AUG-2006'. I thought that TO_CHAR(MYTIMESTAMP,'DD-MON-YYYY') < '01-AUG-2006' would do it, but someone else from work told me to use TO_DATE(SUBSTR(TO_CHAR(MYTIMESTAMP), 1, 9), 'DD-MON-RRRR') '01-AUG-2006' but i'm sure if he's right or not. Could you explain it, please? Why would you want to compare the date as a string? You want to know if your timestamp is before the 1st of August 2006, right? Then use: TRUNC(MYTIMESTAMP) < TO_DATE('01-AUG-2006', fmt_string) TO_CHAR(MYTIMESTAMP,'DD-MON-YYYY') < '01-AUG-2006' This will compare strings, and is most likely not what you want! '01-AUG-2006' < '01-JAN-2001' < '02-MAY-0000' - for STRINGS TO_DATE(SUBSTR(TO_CHAR(MYTIMESTAMP), 1, 9), 'DD-MON-RRRR') '01-AUG-2006' but i'm sure if he's right or not. Could you explain it, This does make even less sense to me ... best, Martin |
#6
| |||
| |||
|
![]() |
| Thread Tools | |
| Display Modes | |
| |