1

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') ;
    }
2
  • Try this $date = date("F j, y",$row_date); echo $date; Commented Apr 8, 2015 at 10:55
  • It might be returning within correct form but you might be echoing it in wrong way Commented Apr 8, 2015 at 11:00

1 Answer 1

1

You need to pass $row_date to every date() call.

echo date('Y', $row_date) ;
Sign up to request clarification or add additional context in comments.

1 Comment

Wow, that was sharp. You´re right, I did only pass date() call to F j Y. I´ve got to try adding w d n into the "date" function and see if that works.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.