I have a table that contains a datetime column in datetime format, see picture for example.

I need to convert this timestamp to YYYYMMDD in int, something like this:

I'm trying this query, but it does not work.
select Cast(Cast(Cast (DATETIME AS DATE Format 'YYYYMMDD') AS VARCHAR(8))AS INT) AS DATE_KEY
FROM TBL_A
to_char converts a date using a format::int casts to intwith data as (
select current_timestamp() datetime
)
select to_char(datetime, 'YYYYMMDD')::int
from data
(with that said, I wouldn't recommend this type of int representation for a date)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With