I am using below query to parse date in presto:
SELECT date_parse(t.up_date, '%c/%e/%Y %l:%i:%s %p') from table t
Sample date is: 4/11/2021 12:30:00 PM
But sometime we get date which is not cannot be parsed like "testdate"
(Any string which is not date)
How can I skip such dates in my query? My query should look like:
select date_parse(t.up_date, '%c/%e/%Y %l:%i:%s %p')
from table t
where <skip the date that does not parse>
Use
try()
. Normallydate_parse()
fails on wrong date format. If you addtry()
, it will produceNULL
s for wrong dates, you filter NULL records like this:Also you can try to parse different formats using coalesce() to pick successfully parsed:
In such way you can try parsing different formats which can be in your data.