I need to get all the records from a table that has a date not matching with the format yyyy-MM-dd.
Here, column ID is unique bigint column. start_date is of varchar datatype.
Sample input:
Expected output:
Thanks
I need to get all the records from a table that has a date not matching with the format yyyy-MM-dd.
Here, column ID is unique bigint column. start_date is of varchar datatype.
Sample input:
Expected output:
Thanks
Copyright © 2021 Jogjafile Inc.
Use regexp_like:
This will work for '11-12-200' and 'None'.
If you want to include NULL values as well, add additional condition:
More strict date regexp is
'^\d{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])$'
This will restrict month to
01
..12
and day to01
..31
and will not allow other characters before and after date(^
and$
anchors are used).One more simple and powerful method
is to use
try_cast(col as date)
- it will return NULL if not possible to cast:This will also restrict wrong dates like Feb 30 (2000-02-30)