日期时间转换的SQLSRV PHP插入问题
在尝试输入日期时,在sql server数据库中执行插入查询时遇到问题。我的问题是: 从字符转换日期和/或时间时转换失败 插入日期时间时的字符串 我使用的查询是:日期时间转换的SQLSRV PHP插入问题,php,sql-server,datetime,sqlsrv,Php,Sql Server,Datetime,Sqlsrv,在尝试输入日期时,在sql server数据库中执行插入查询时遇到问题。我的问题是: 从字符转换日期和/或时间时转换失败 插入日期时间时的字符串 我使用的查询是: $sqlpedido = "INSERT INTO dbo.I_Pedido (id_cliente, Fecha, total, Comentario, portes, estado, FPago, id_destino, FormaEnvio) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)&quo
$sqlpedido = "INSERT INTO dbo.I_Pedido (id_cliente, Fecha, total, Comentario, portes, estado, FPago, id_destino, FormaEnvio) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)";
$params = array($ClienteID, $newformat, $gtotal, $cusnote, $shiptotal, '0', $paymethod,$id_destino, $shipmethod);
$stmt26 = $conn5->prepare($sqlpedido);
$stmt26->execute($params);
变量$newformat
出现问题,我尝试使用不同的形式将Woocommerce提供的日期字符串转换为datetime:
备选案文1:
$dcreated = $order->get_date_created();
$d = new DateTime($dcreated);
$timestamp = $d->getTimestamp();
$formatted_date = $d->format('c');
备选案文2:
$dcreated = $order->get_date_created();
$time = strtotime($dcreated);
$newformat = date('c',$time);
但是没有一个选择解决了这个问题。。。你能帮我吗
谢谢 在SQL Server中将日期时间值作为文本传递到
datetime
列时,需要使用明确的日期时间格式(yyy-mm-ddThh:mm:ss
)
函数get\u date\u created()
返回值,因此可以选择使用PHP方法格式化值:
<?php
...
$newformat = $order->get_date_created()->format('Y-m-d\TH:i:s');
$sqlpedido = "
INSERT INTO dbo.I_Pedido (id_cliente, Fecha, total, Comentario, portes, estado, FPago, id_destino, FormaEnvio)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
";
$params = array($ClienteID, $newformat, $gtotal, $cusnote, $shiptotal, '0', $paymethod, $id_destino, $shipmethod);
$stmt26 = $conn5->prepare($sqlpedido);
$stmt26->execute($params);
...
?>
给出一个示例$order->get_date_created()代码>我正在尝试所有这些方法,因为直接使用这些方法不起作用不,我是说你能举一个$order->get_date_created()的例子吗
@josesd$newformat
-一个PHP日期时间对象或一个字符串,代表一个日期时间值的实际值是多少?您是否正在使用Micorosft SQL Server(sqlsrv
标记是关于SQL Server的)?$order->get_date_clated();return 2020-09-14T05:21:42+00:00,我读到它,我认为它的格式正确,但它返回了错误