开发者

How to Convert this date to mySQL time using PHP?

20101109-240000 or 20101109-235959

How to convert the date开发者_开发技巧 format above into MySQL format, Y-m-d H:i:s

Thank You


$mysqldate = preg_replace('/(\d{4})(\d{2})(\d{2})\-(\d{2})(\d{2})(\d{2})/', '$1-$2-$3 $4:$5:$6',$date)


Use STR_TO_DATE() MySQL function :

SELECT STR_TO_DATE('20101109-235959', '%Y%m%d-%H%i%s');
-- 2010-11-09 23:59:59

P.S. 20101109-240000 wouldn't work because it is not a valid timestamp.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜