从MySQL数据库检索时间戳值将返回当前日期


Retrieving timestamp value from MySQL database returns current date

检索"时间戳";值,我的php文件总是返回当前日期,而不是将行添加到MySQL表的时间戳日期。

我确信在MySQL中添加新行时时间戳是正确的,我检查了phpMyAdmin,并且值是正确的。但是,当我要求使用php检索它们时,所有条目都会作为当前日期返回,显示我要求MySQL返回数据的日期,而不是原始的时间戳值。

我在MySQL中的时间戳属性如下:

name:fecha/type:TIMESTAMP/null:FALSE/默认值:CURRENT_TIMESTAMP

我使用以下代码来检索时间戳值(我必须创建一些变量来将英语时间戳翻译成西班牙语):

    $query = mysql_query ("SELECT * FROM news;");
    while ($row = mysql_fetch_array ($query)){
        
            $row_date = strtotime ($row["fecha"]);
            date ("F j, Y", $row_date);
            $dias = array("Domingo","Lunes","Martes","Miercoles","Jueves","Viernes","Sábado");
            $meses = array("Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre");
                    
    echo $dias[date('w')]." ".date('d')." de ".$meses[date('n')-1]. " del ".date('Y') ;
    }

您需要将$row_date传递给每个date()调用。

echo date('Y', $row_date) ;