Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP: why is strtotime() returning "NOW()"?
    primarykey
    data
    text
    <p>I'm calling <code>strtotime()</code> on a formatted datetime string and for some reason it always returns <code>NOW()</code>...</p> <p>If my formatted datetime string (stored in the <code>last_seen</code> attribute) is: <code>2013-06-13 07:13:04</code></p> <p>and I write the following code:</p> <pre><code>echo $user-&gt;last_seen; echo date('F j, Y', strtotime($user-&gt;last_seen)); </code></pre> <p>The output I get is:</p> <pre><code>NOW() January 1, 1970 </code></pre> <p>What on earth is going wrong here??? This is definitely not the expected result. The string is stored in a MySQL database, if that makes any difference.</p> <p><strong>Edit:</strong> by request, the code used to create the attribute in the database is:</p> <pre><code>$user-&gt;last_seen = date('Y-m-d H:i:s'); $user-&gt;save; </code></pre> <p><strong>Edit 2:</strong> by request, the code used to pull the users table, with the user we want, is:</p> <pre><code>$user = User::find($user_id); </code></pre> <p>(not very helpful, lol). </p> <p><strong>Edit 3:</strong> if I <code>var_dump($user-&gt;last_seen)</code> the result is:</p> <pre><code>object(Laravel\Database\Expression)#40 (1) { ["value":protected]=&gt; string(5) "NOW()" } </code></pre> <p><strong>Edit 4:</strong> If I echo <code>var_dump(strtotime($user-&gt;last_seen))</code> the result is:</p> <pre><code>bool(false) </code></pre> <p><strong>Edit 5:</strong> this problem was a result of me being an idiot, but some fine debugging was done by everyone who posted. Read the answers if you are interested. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload