note 86326 added to ref.datetime

From: Date: Mon, 13 Oct 2008 11:11:28 +0000
Subject: note 86326 added to ref.datetime
Groups: php.notes 
Request: Send a blank email to php-notes+get-145311@lists.php.net to get a copy of this message
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'; } ?> ---- Server IP: 69.147.83.197 Probable Submitter: 195.188.195.198 ---- Manual Page -- http://www.php.net/manual/en/ref.datetime.php Edit -- https://master.php.net/note/edit/86326 Del: integrated -- https://master.php.net/note/delete/86326/integrated Del: useless -- https://master.php.net/note/delete/86326/useless Del: bad code -- https://master.php.net/note/delete/86326/bad+code Del: spam -- https://master.php.net/note/delete/86326/spam Del: non-english -- https://master.php.net/note/delete/86326/non-english Del: in docs -- https://master.php.net/note/delete/86326/in+docs Del: other reasons-- https://master.php.net/note/delete/86326 Reject -- https://master.php.net/note/reject/86326 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#145311) next »