0

In my mysql database dateTime is stored in the following form.

00000-00-00 00:00:00

In my php I want to convert it to tiemStamp form like this.

136716425

I tried using

$date2->getTimestamp();

without success, what function should I use to change the format to timestamp?


$sql = "SELECT * FROM temp_user";
$result = mysql_query($sql);
while ($row = mysql_fetch_assoc($result)) {

    $date1 = new DateTime();
    $date2 = $row[dateTime];

    echo $date1->getTimestamp();
    echo $date2->getTimestamp();



}
4

1 回答 1

4

MySQL 有一个内置函数用于调用UNIX_TIMESTAMP

SELECT UNIX_TIMESTAMP(NOW())

更新

$sql = "SELECT *,UNIX_TIMESTAMP(dateTime) unx FROM temp_user";
$result = mysql_query($sql);
while ($row = mysql_fetch_assoc($result)) 
{
    $var = $row['unx'];
    // other codes
}
于 2013-04-28T15:57:40.993 回答