将SQL Server日期时间转换为mysql日期时间

时间:2012-08-17 19:23:35

标签: php mysql sql-server datetime

  

可能重复:
  How to convert DateTime to VarChar

实施例

如何将SQL日期时间(例如08/14/2012 1:05:18 PM)转换为mysql方式(即Y-m-d H:i:s)?

3 个答案:

答案 0 :(得分:6)

取决于您想要转换它的位置。

直接转换SQL:

convert(varchar(23), getdate(), 121)

使用datestrtotime函数的PHP:

date("Y-m-d H:i:s ", strtotime("08/14/2012 1:05:18 PM"));

答案 1 :(得分:2)

在PHP中更改日期的格式如下:

<?
$date = date("Y-m-d H:i:s ", strtotime("08/14/2012 1:05:18 PM"));
echo $date;
?>

答案 2 :(得分:2)

$var = "08/14/2012 1:05:18 PM";
echo date('Y-m-d H:i:s', strtotime($var));