I am using an Informix database. I want to get the difference between two dates, and the data type of return value must be an integer. The SQL looks like:
select (today - to_date('20121201','%Y%m%d')) from your_table_name
However, when I execute the SQL it returns 45 and certainly the computed value is not the integer type.
What’s the date type of the value? How can I cast the value to integer?
The TO_DATE function is an Oracle import, and returns an Oracle DATE type in Oracle (hence the name), but the Oracle DATE type corresponds to an Informix DATETIME type. So, the Informix implementation of the TO_DATE() function returns a DATETIME type.
Problem
Solution
The solution for your expression is to apply the DATE function to the output of TO_DATE, or cast it to type DATE.