I was trying to use the TRYCAST function to check if a string was a DATE or not.
But when I do this :
SELECT trycast( '20170505' AS DATE (FORMAT 'YYYYMMDD') )
I get an error. This works :
trycast( '2017-05-05' AS DATE )
But I would've liked to avoid using some SUBSTR function in my cast.
Is this possible ?
The first fails because it is invalid syntax (the second is the only documented syntax for TryCast).
I think you'll have to use SUBSTRING because the obvious alternatives involve CASTing the original string to a DATE, but that will fail if you have invalid data which possibly negates the reason for using TryCast in the first place.