I have a requirement to convert MM/DD/YYYY to YYYYMMDD in amazon redshift database.
My result of this query gives me some weird result. Can some one please help me.
select to_date ('07/17/2017','YYYYMMDD');
0007-07-20
If you just wish to convert the hard-coded string into a DATE
:
select to_date('07/17/2017', 'MM/DD/YYYY')
If you have a column already formatted as DATE
, then use:
to_char(fieldname, 'YYYYMMDD')
Combining the two concepts:
select to_char(to_date('07/17/2017', 'MM/DD/YYYY'), 'YYYYMMDD')
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