1

I have dates in different format :

Date 1 : 30-JAN-14

Date 2 : 2014-01-30 10:06:04.0

I am trying to compare the two dates using the following :

to_char(date2,'YYYY-MM-DD HH24:MM:SS') <> to_char(date1,'dd-MON-YY')

But it is giving the following error for the date1 part :

Lietral does not match format String 

I tried comparing them directly

date2<>date1

I am gtting the same error again

EDIT : Date2 is varchar and Date1 is DATE

2
  • 3
    Do you have dates or strings? You talk about dates but dates do not have formats. Strings that represent dates have a format. But then it wouldn't make sense to call to_char on a character string, it would only make sense to call to_date on character strings. Also, what would equality look like to you? Do you want to ignore the time component on the second value when comparing the two? Commented Sep 11, 2014 at 2:07
  • Date2 is a varchar column Date 1 column is of type DATE 2) I want to ignore the time component of Date2. I just want to check if the two dates are unequal Commented Sep 11, 2014 at 2:10

3 Answers 3

1

Probably easiest to use substr and truncate the timestamp from the date2 column. Then you can use to_date to compare:

select *
from sometable
where date1 <> to_date(substr(date2,1,10), 'YYYY-MM-DD')
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks . I am not getting any errors. But the two dates are being treated differently. I want 30-JAN-14 and 2014-01-30 TIME as equal. Can you please help me with this
@user2133404 -- did you review the fiddle? It returns those as the same based on your sample data.
0

You should be Date type conversion string is the same format for comparison

Comments

0

You can try this. to_char(date2,'YYYY-MM-DD') <> to_char(date1,'YYYY-MM-DD')

2 Comments

Invalid Number - I think its in date 1
with sysdate not works this method :) he return dd/mm/yy and not dd/mm/yyyy

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.