开发者

MySql's date separator in str_to_date

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

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜