I am working on a .Net WinForms application that connects to an old RDB database ...
Some fields for dates are stored as integers (suppose 2010-01-04 was an integer 20100104)
In the .Net world, I would rather work with datetime objects, and I was able to convert an integer to a date that just looks so ugly, takes up a lot of lines, is error prone and I wonder if anyone can improve it ... Thanks, heaps!
Note. I can’t edit the database, so creating any form of “function” is out of the question ...
Here is my current way of choosing an integer as datetime:
select
CAST(
SUBSTRING(DATE_COL AS VARCHAR(8)) FROM 1 FOR 4) ||
'-' ||
SUBSTRING(CAST(DATE_COL) AS VARCHAR(8)) FROM 5 FOR 2) ||
'-' ||
SUBSTRING(CAST(DATE_COL) AS VARCHAR(8)) FROM 7 FOR 2) ||
' 00:00:00'
AS TIMESTAMP) AS DATE_COL
from MY_TABLE
where ...
source
share