开发者

How to Convert this date to mySQL time using PHP?

开发者 https://www.devze.com 2023-01-25 11:59 出处:网络
20101109-240000 or 20101109-235959 How to convert the date开发者_开发技巧 format above into MySQL format, Y-m-d H:i:s

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

精彩评论

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