开发者

PHP - Format date/time

开发者 https://www.devze.com 2023-03-03 19:32 出处:网络
Suppose I got the s开发者_如何学JAVAtring of date look like \"01:07:13 May 07, 2011 PDT\", how can I format it to the format like \"2007-07-20 17:20:07\" (data type - timestamp) so that I can insert i

Suppose I got the s开发者_如何学JAVAtring of date look like "01:07:13 May 07, 2011 PDT", how can I format it to the format like "2007-07-20 17:20:07" (data type - timestamp) so that I can insert it to MySQL


<?php
$date="01:07:13 May 07, 2011 PDT";
echo date('Y-m-d h:i:s',strtotime($date));
?>

DEMO


$date="01:07:13 May 07, 2011 PDT";
$query = "UPDATE table SET datefield = str_to_date('$date','%M %d,%Y PDT') 
          WHERE ...."

See: http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_str-to-date

0

精彩评论

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