The following query:
select cdate from rprt where cdate <= TO_CHAR(sysdate, 'YYYY/MM/DD-HH24-MI-SS-SSSSS') and ryg='R' and cnum='C002';
return: 2013/04/27-10:06:26:794
as stored in the table.
I want to get the date only as : 27-04-2013
and get the number of days between the resul tdate and sysdate.
This is exactly what
TO_DATE()
is for: to convert timestamp to date.Just use
TO_DATE(sysdate)
instead ofTO_CHAR(sysdate, 'YYYY/MM/DD-HH24-MI-SS-SSSSS')
.SQLFiddle demo
UPDATE:
Per your update, your
cdate
column is not realDATE
orTIMESTAMP
type, butVARCHAR2
. It is not very good idea to use string types to keep dates. It is very inconvenient and slow to search, compare and do all other kinds of math on dates.You should convert your
cdate
VARCHAR2
field into realTIMESTAMP
. Assuming there are no other users for this field except for your code, you can convertcdate
to timestamp as follows:SQLFiddle Demo
try this type of format:
Convert Timestamp to Date as mentioned below, it will work for sure -
Use the function cast() to convert from timestamp to date
For more info of function cast oracle11g http://docs.oracle.com/cd/B28359_01/server.111/b28286/functions016.htm#SQLRF51256
If you want the value from your timestamp column to come back as a date datatype, use something like this:
This format worked for me, for the mentioned date format i.e.
MM/DD/YYYY