Problem Description
Having a look on the PHP documentation, the following two methods of the `DateTime` object would both seem to solve my problem:
- <a href="http://au.php.net/manual/en/datetime.diff.php">DateTime::diff</a> : Get the difference and use that to determine which is more ancient.
- <a href="http://au.php.net/manual/en/datetime.gettimestamp.php">DateTime::getTimestamp</a> : Get the UNIX timestampt and compare those.
Both these methods are marked in the <a href="http://au.php.net/datetime">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&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a">Googled</a> the problem and found an eclectic range of solutions, none of which answer my very simple requirements:
- How do I compare two DateTime objects?
- Where can I find the doco for previous PHP versions? Specifically version 5.2.8?
For some context, I have the following 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 < $start_dt)
Apparently there is no comparison operator on this guy.
Edit
---
*Apparently* 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 :).
AI-Generated Solution
Powered by LMSouq AI · GPT-4.1-mini
Analyzing problem and generating solution…
Was this solution helpful?