I call strtotime() on a formatted datetime string and for some reason always returns NOW() ...
If my formatted date and time string (stored in the last_seen attribute): 2013-06-13 07:13:04
and I write the following code:
echo $user->last_seen; echo date('F j, Y', strtotime($user->last_seen));
The output I get is:
NOW() January 1, 1970
What is going on here? This is definitely not the expected result. The string is stored in the MySQL database, if that matters.
Edit: upon request, the code used to create the attribute in the database:
$user->last_seen = date('Ymd H:i:s'); $user->save;
Edit 2: on request, the code used to pull out the user table with the right user:
$user = User::find($user_id);
(not very useful, lol).
Edit 3: if I var_dump($user->last_seen) result:
object(Laravel\Database\Expression)#40 (1) { ["value":protected]=> string(5) "NOW()" }
Edit 4: If I echo var_dump(strtotime($user->last_seen)) , the result is:
bool(false)
Edit 5: This problem was the result of being an idiot, but some subtle debugs were done by everyone who posted. Read the answers if you are interested.
source share