srujk
srujk

Reputation: 21

Snowflake query to validate the date field

I need to validate date columns it should have case statement if the the date format it should pass or any other format is should fail and if the date format is any date format it should convert to DD-MM-yyyy format. Can anyone suggest me in snowflake i need to validate the code .

Upvotes: 1

Views: 1087

Answers (1)

Lukasz Szozda
Lukasz Szozda

Reputation: 176324

Using TRY_TO_DATE. When the string does not match the provided format NULL is returned instead.

SELECT col, CASE WHEN TRY_TO_DATE(col, 'DD-MM-yyy') IS NULL THEN 'matches format'
                 ELSE 'does not match format'
            END
FROM tab;

Upvotes: 1

Related Questions