我需要在 datetime
类型的 SQL 字段中引入我的日期和时间。目前,日期的格式是mm/dd/yyyy
,我的时间格式是hh:ii
。我尝试将此数据发送为
$datetime=$date。' '.$time
,但不起作用,无论输入是什么,在数据库中我总是有 00-00-00 00:00:00:00
。
我该如何解决这个问题?
最佳答案
<?php
$date="01/01/2017"; // This is the format you mentioned
$time="22:11"; // This is the format you mentioned
$time=strtotime("$date $time"); //if strtotime() confuses mm with dd, use mktime()
echo date("Y-m-d H:i:s",$time); // MySQL Format
?>
关于php - 如何正确格式化 SQL 日期时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19676047/