【发布时间】:2013-05-03 16:42:31
【问题描述】:
我正在尝试将 PHP 中的日期字符串作为时间戳数据类型保存到 MySQL 数据库中。我发现了很多关于这个的帖子,但没有一个对我有用。这是我尝试过的:
$date = $_POST['date'];
$timestamp = date("m/d/Y", strtotime($date));
$sql = "insert into sale(service, amount, date, customerid_fk) values('$service', '$amount', '$timestamp', '$id');";
但在数据库中,我只得到:
0000-00-00 00:00:00
POST 对象的输入字符串是05/30/2013。非常感谢您的支持!
【问题讨论】:
-
mySQL 需要
Y-m-d格式的时间戳。相应地更改格式字符串,你会很好。 -
你已经检查过这个了吗? stackoverflow.com/questions/2501915/…
-
如果要将参数作为字符串传递,则将其转换为数据库使用 STR_TO_DATE(yourstring, '%m/%d/%Y')
标签: php mysql date format timestamp