note 86326 deleted from ref.datetime by tularis
| From: | tularis@php.net | Date: | Mon, 13 Oct 2008 13:29:54 +0000 |
| Subject: | note 86326 deleted from ref.datetime by tularis | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-145313@lists.php.net to get a copy of this message | ||
Note Submitter: php dot net at juamei dot com
----
If you just need to know if one Date is before another, the simplest way seems to be to convert them
to Strings of the format (yyyymmdd) and then compare the resulting numbers. So something like:
<?php
$today = new DateTime();
$anotherdate = new DateTime( '2008-10-12' );
$today_int = (int)$date->format('Ymd');
$anotherdate_int = (int)$anotherdate ->format('Ymd');
if( $today_int < $anotherdate_int ){
echo '$anotherdate is in the future';
}elseif( $today_int > $anotherdate_int ){
echo '$anotherdate is in the past';
}else{
echo '$anotherdate is today';
}
?>