Reputation: 49
When retrieving "timestamp" value from MySQL table, my php file always returns the current date, not the timestamp date in which the row was added to MySQL table.
I know for sure that timestamp works right when adding new rows in MySQL, I´ve checked phpMyAdmin and values are right. But when I ask to retrieve them using php, all the entries are returned as current date, showing the date in which I´m asking MySQL to return the data, not the original timestamp value.
My timestamp attributes in MySQL are the following ones:
name: fecha / type: TIMESTAMP / null: FALSE / default value: CURRENT_TIMESTAMP
I´m using the following code to retrieve the timestamp values (I had to create a few variables to translate the English timestamp to Spanish):
$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') ;
}
Upvotes: 1
Views: 800
Reputation: 41
You need to pass $row_date to every date() call.
echo date('Y', $row_date) ;
Upvotes: 1