0
votes

One column is formatted like this: dd/mm/yyyy The other is formatted like this: yyyymmdd How do I create a select statement which lets me compare these two columns? They are both varchar. I'm running a db2 database.

2
If they are formatted differently, what data type are they? Convert them to DATE data type - data_henrik

2 Answers

0
votes

I DB2, you can use TO_DATE() to convert both string dates to TIMESTAMP datatypes (note that TO_DATE is a synonym for the TIMESTAMP_FORMAT scalar function).

You can then safely compare them:

to_date(col1, 'dd/mm/yyyy') = to_date(col2, 'yyyymmdd')
0
votes

I solved it like this. I used substr:

substr(COLUMN_NAME, 7,4) || substr(COLUMN_NAME,4,2) || sub-str(COLUMN_NAME,1,2)

Posted on behalf of the question asker