Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP - Date as Wrong Data Type
    primarykey
    data
    text
    <p>So, PHP apparently feels like being a moron today. Or maybe it's me. Or both.</p> <pre><code>function before($test,$bar) { $test = date_create($test); $bar = date_create($bar); $diff = date_diff($bar,$test); $diff = $diff-&gt;format('%r%a') * 1; return $diff&lt;0; } </code></pre> <p>It refuses to accept that a date generated by the following means:</p> <pre><code>date('m-d-Y', strtotime($date)); </code></pre> <p>...is anything but a BOOLEAN! If I output the result, it comes out as a string, but - with PHP pining to confound me - <code>before()</code> treats it like something that it isn't. There is NOTHING here that should convert it to a boolean. I can feed it a string directly, and it works fine. Give it a date from a piece of code specifically made for the very purpose, well, we can't have that 'cause...</p> <pre><code>Warning: date_diff() expects parameter ... to be DateTime, boolean given </code></pre> <p>I thought, "fine, I'll give you your parser's desire."</p> <pre><code>function before($test,$bar) { $test = new DateTime(date('Y-m-d',strtotime($test))); $bar = new DateTime(date('Y-m-d',strtotime($bar))); $diff = $bar-&gt;diff($test); $diff = $diff-&gt;format('%r%a') * 1; return $diff&lt;0; } </code></pre> <p>No change in result whatsoever. I gave it what it wanted, or at least what it <em>said</em> it wanted (I think), and it still rejects me. Coding mimicking reality.</p> <p>I'm not terribly comfortable with dates yet. I'm also not terribly comfortable yet with how PHP handles the time of year. Any advice? And maybe how to get this to work, too?</p> <h3>Edit</h3> <p>Running <code>var_dump($test)</code></p> <pre><code>object(DateTime)#7 (3) { ["date"]=&gt; string(19) "1970-01-01 00:00:00" ["timezone_type"]=&gt; int(3) ["timezone"]=&gt; string(13) "Europe/Berlin" } </code></pre>
    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