I allow users to enter dates as 15-10-2010 and 15/10/2010. Problem is, I can only specify one separator type in mysql'开发者_Python百科s str_to_date. So if a user enters 15-10-2010, then STR_TO_DATE('15-10-2010','%d-%m-%Y')
would work fine. But if the user did 15/10/2010, I get a null value in the database column. Is there a way to tell mysql to all both - and / as the seperator?
You could use the Replace function in mysql.
Something like this:
STR_TO_DATE(REPLACE('15/10/2010', '/', '-'), '%d-%m-%Y')
Hope this helps, Arne
精彩评论