gpt4 book ai didi

php - 将 PHP 日期字符串作为时间戳保存到 MySQL 数据库中

转载 作者:可可西里 更新时间:2023-11-01 06:31:37 24 4
gpt4 key购买 nike

我正在尝试将 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。非常感谢您的支持!

最佳答案

这可能对你有用:

$date =  $_POST['date'];
$timestamp = date('Y-m-d H:i:s', strtotime($date));

$sql = "insert into sale(service, amount, date, customerid_fk) values('$service', '$amount', '$timestamp', '$id');";

关于php - 将 PHP 日期字符串作为时间戳保存到 MySQL 数据库中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16457832/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com