Hrodger
Hrodger

Reputation: 1278

Convert Date to interval string oracle

I have the following validation:

DATE1 + INTERVAL to_char(DATE2, 'HH24:MI:SS') HOUR TO SECOND > DATE3;

But it keeps me saying that the operator is not valid. What am I doing wrong?

Upvotes: 1

Views: 1792

Answers (1)

David Faber
David Faber

Reputation: 12485

It looks like you're trying to get the time part from DATE2 and add it to DATE1? I'm afraid that Oracle doesn't recognize TO_CHAR(date2...) as an INTERVAL literal even though it appears to be in the correct format. I would try this instead (good old-fashioned Oracle date arithmetic):

date1 + ( date2 - TRUNC(date2) ) > date3;

You could also do the following:

 date1 + TO_DSINTERVAL('0 ' || TO_CHAR(date2, 'HH24:MI:SS')) > date3;

where date2 is converted to a DAY TO SECOND INTERVAL (I'm using 0 for the number of days since you want only the time part).

Upvotes: 2

Related Questions