[英]php convert string to SQL type DateTime
I want to be able to compare an input of $date, which is a string, with a value from the database with the type of "datetime". 我希望能够将$ date的输入(它是一个字符串)与数据库中“ datetime”类型的值进行比较。 Here's my code below.
这是我的下面的代码。 It outputs as a string type instead of the desired datetime type.
它输出为字符串类型,而不是所需的日期时间类型。 Can you please help me out?
你能帮我吗?
<?php
$string="2013-04-19 14:08:10";
$timestamp = strtotime($string);
$date = date("Y-m-d H:i:s", $timestamp);
?>
<?php var_dump($date);?>
this is the output 这是输出
string '2013-04-19 14:08:10' (length=19)
Thanks so much for your help. 非常感谢你的帮助。
对于MySQL datetime数据类型,可以使用:
$date = new \DateTime('2013-04-19 14:08:10');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.