chickanna
asked on
oracle date comparision
experts... how do i compare two dates in oracle. I have 2 variables
first(v_date1) of varchar2(30) where I get a date in the format 'yyyy-mm-dd hh24:mi' and have another variable(v_date2) of varchar2(30) where i get a value from a table of 'date' column type by doing
select to_char(i_date )
into v_date2
from table1
where col1 = some_value
I want to see if v_date2 is less than v_date1. How do i do this????
first(v_date1) of varchar2(30) where I get a date in the format 'yyyy-mm-dd hh24:mi' and have another variable(v_date2) of varchar2(30) where i get a value from a table of 'date' column type by doing
select to_char(i_date )
into v_date2
from table1
where col1 = some_value
I want to see if v_date2 is less than v_date1. How do i do this????
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
if you must have both variables as string type then force the v_date2 to have a consistent format
to_char(i_date,'yyyy-mm-dd hh24:mi')
that format should allow for direct string comparison.
or you could convert both back to dates with
to_date(v_date1,'yyyy-mm-d d hh24:mi')
to_date(v_date2,'yyyy-mm-d d hh24:mi')
to_char(i_date,'yyyy-mm-dd
that format should allow for direct string comparison.
or you could convert both back to dates with
to_date(v_date1,'yyyy-mm-d
to_date(v_date2,'yyyy-mm-d
to_date(v_date1, 'yyyy-mm-dd hh24:mi') > to_date( v_date2, 'yyyy-mm-dd hh24:mi' )