Can't convert CURRENT_TIMESTAMP to specified format

I’m trying to do a simple date conversion and I keep getting a malformed error.

SELECT TO_DATE(CURRENT_DATE, 'YYYYMMDD')
SELECT TO_DATE(CURRENT_TIMESTAMP, 'YYYYMMDD')

Error I’m getting:

FUNCTION ERROR: Input text cannot be formatted to date Details Invalid format: "2019-03-28" is malformed at "-03-28" Input text 2019-03-28 SqlOperatorImpl PROJECT Location 1:0:3 SqlOperatorImpl PROJECT Location 1:0:3 Fragment 1:0

Not sure what the issue is. This should be super simple.

I want to convert to ISO standard. ‘YYYYMMDD’

Hi,

TO_DATE converts text to a date and the argument should be the format to use when parsing the text. In your case it looks like the text is of format YYYY-MM-DD.

1 Like

Thanks for your quick response @doron

So looking through the docs https://docs.dremio.com/sql-reference/sql-functions/datetime-functions.html

It looks like there isn’t a function similar to Convert() in SQL Server.

You can then use TO_CHAR(“column”, ‘YYYYMMDD’) to convert it to the ISO standard string representation.