DANIEL HERNANDEZ
DANIEL HERNANDEZ

Reputation: 23

concat columns and then convert to date and finally compare in DB2 (IBM as400)

I have a db similar to the picture. I want to have the data from three days ago from the current day. I suppose that I have to concat the three columns and then convert to date for finally compare with the current day. I tried this:

select * from MYTABLE where date(concat("-",concat("-",MYTABLE.YEAR,MYTABLE.MONTH),MYTABLE.DAY))>= CURRENT DATE -3

I don't know if it is correct, because I'm connected to IBM as400

Help me please

Thanks.

enter image description here

Upvotes: 0

Views: 1144

Answers (1)

Player1st
Player1st

Reputation: 1605

If all of the data matches the example you posted, the following should be enough to do the job:

select *
from MYTABLE
where date(trim(ltrim(YEAR, '0')) || '-' || lpad(trim(MONTH), 2, '0') || '-' || lpad(trim(DAY), 2, '0')) >= current_date - 3 days

Upvotes: 1

Related Questions