Search code examples
phpmysqldateregistration

Fetching join date from mysql database and echoing it as a readable format


I want to fetch the join date of users from my database and then echo it out into a readable format. Here's my code:

function date_registered($user_id) {
$sqldate = mysql_fetch_array(mysql_query("SELECT `date_registered` FROM `users` WHERE `user_id` = $user_id"));
$date = strtotime($sqldate['date_registered']);
return date("j F Y", $sql);}

and the echo:

echo    '<p>Joined: ' . date_registered($user_id) . '</p>';

However, when using this code it echoes out "1 January 1970" as the join date, instead of the 22nd of May 2015 that is stored in the database.

Any idea how I can fix this?


Solution

  • You want return date("j F Y", $date); instead of return date("j F Y", $sql);.