将C#datetime转换为php mysql [关闭]

将C#datetime转换为php mysql [关闭]

问题描述:

I have to save DateTime which is coming from .Net Application in a MySql database with PHP, but I am not able to do so.

I have tried this for example, but it's not working:

    $date = "7/24/2013 11:40:53 AM";
    $datetime = new DateTime ($date);
    print $datetime->date;

What is happening is: The code is working fine when I am debugging this code line by line, means it is printing 2013-07-24 11:40:53, but without debugging it is not printing, I am not able to understand why is this happening; I am stuck.

Simply use format method of DateTime object.

$date = "7/24/2013 11:40:53 AM";
$datetime = new DateTime ($date);
echo $datetime->format('Y-m-d H:i:s');

You can try strtotime() function.

echo strtotime($datetime);

Make use of the FORMAT

<?php
$date1 = "7/24/2013 11:40:53 AM";

$datetime = new DateTime ($date1);
print $datetime->format('Y/m/d H:i:s');

OUTPUT

2013/07/24 11:40:53