开发者

Isolate values based on format in mysql

开发者 https://www.devze.com 2023-01-28 13:55 出处:网络
I have a date column that is really messed up. It had %m/%d/%y values that I have reformatted to %Y-%m-%d like they should be.

I have a date column that is really messed up.

It had %m/%d/%y values that I have reformatted to %Y-%m-%d like they should be.

Now I am discovering that there are records that have a date in them that are %d%y%m!!

Now I need to only select those values that look like 000000 and nothing that is 0000-00-00 o开发者_如何学Gor 0000/00/00.

What is the best way to isolate that format?

Thanks


You should use the date column types to avoid such issues. This also allows you to use the mysql date and time functions

To solve your issue you can use select * from mytable where mydate not like '____-%__%__' and not like '____/__/__' (note the number of underscores).

If this is not enough for you, use a mysql regular expression.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号