note 104055 added to function.date
| From: | milespickens+php at gmail dot com | Date: | Fri, 20 May 2011 01:55:31 +0000 |
| Subject: | note 104055 added to function.date | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-179892@lists.php.net to get a copy of this message | ||
I needed to find out the Greater or Lesser dates for a few results sets. I'm not running 5.3
so I came up with this function to return either the greater or lesser date. The function is
expecting dates in the MM/DD/YYYY format and the 3rd variable that is is looking for is either G or
L so it will know whether to return the lesser or greater date.
function greater_lesser_date($date1,$date2,$gl = false){
///$gl is expecting either a G or an L to know whether you want
///greater or lesser returned
$d1m = substr($date1,0,2);
$d1d = substr($date1,3,2);
$d1y = substr($date1,6,4);
$d1 = mktime(0,0,0,$d1m,$d1d,$d1y);
$d2m = substr($date2,0,2);
$d2d = substr($date2,3,2);
$d2y = substr($date2,6,4);
$d2 = mktime(0,0,0,$d2m,$d2d,$d2y);
if( strtoupper($gl) == 'L') {
$date = ($d1>$d2?$d2:$d1);
} else {
$date = ($d1<$d2?$d2:$d1);
}
return date('m/d/Y', $date);
}
----
Server IP: 69.147.83.197
Probable Submitter: 174.127.8.233
----
Manual Page -- http://www.php.net/manual/en/function.date.php
Edit -- https://master.php.net/note/edit/104055
Del: integrated -- https://master.php.net/note/delete/104055/integrated
Del: useless -- https://master.php.net/note/delete/104055/useless
Del: bad code -- https://master.php.net/note/delete/104055/bad+code
Del: spam -- https://master.php.net/note/delete/104055/spam
Del: non-english -- https://master.php.net/note/delete/104055/non-english
Del: in docs -- https://master.php.net/note/delete/104055/in+docs
Del: other reasons-- https://master.php.net/note/delete/104055
Reject -- https://master.php.net/note/reject/104055
Search -- https://master.php.net/manage/user-notes.php