Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I compare two DateTime objects in PHP 5.2.8?
    primarykey
    data
    text
    <p>This seems like something that should be pretty straight forward, but I have been stuck <em>page faulting</em> this problem for a while now, so here goes.</p> <p>Having a look on the PHP documentation , the following two methods of the DateTime object would both seem to solve my problem:</p> <ul> <li><a href="http://au.php.net/manual/en/datetime.diff.php" rel="noreferrer">DateTime::diff</a> : Get the difference and use that to determine which is more ancient.</li> <li><a href="http://au.php.net/manual/en/datetime.gettimestamp.php" rel="noreferrer">DateTime::getTimestamp</a> : Get the UNIX timestampt and compare those.</li> </ul> <p>Both these methods are marked in the <a href="http://au.php.net/datetime" rel="noreferrer">doco</a> as being available in version >= 5.3 (and, not surprisingly, if I try to call them I find they don't exist). I can't find any specific documentation for 5.2.8 so I am not sure if there are equivalent methods in my version. I have <a href="http://www.google.com.au/search?q=compare+DateTime+PHP&amp;ie=utf-8&amp;oe=utf-8&amp;aq=t&amp;rls=org.mozilla:en-US:official&amp;client=firefox-a" rel="noreferrer">Googled</a> the problem and found an eclectic range of solutions, none of which answer my very simple requirements:</p> <ul> <li>How do I compare two DateTime objects?</li> <li>Where can I find the doco for previous PHP versions? Specifically version 5.2.8?</li> </ul> <p>For some context, I have the following code:</p> <pre><code>$st_dt = new DateTime(verifyParam ('start_date')); $end_dt = new DateTime(verifyParam ('end_date')); // is the end date more ancient than the start date? if ($end_dt &lt; $start_dt) </code></pre> <p>Apparently there is no comparison operator on this guy. </p> <p>EDIT: <em>Apparently</em> my assumptions were completely false (thanks Milen for illustrating this so effectively). There is a comparison operator and it works just fine thanks. Sometimes I really miss a compiler. The bug is in the code above, I am sure you will find it much faster than I did :).</p> <p>I look forward to my embarrassment at the simplicity of your solution.</p> <p>EDIT: And sure enough, embarrassment ensues ...</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.
 

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