note 104055 modified in function.date by danbrown
| From: | danbrown@php.net | Date: | Fri, 20 May 2011 14:26:38 +0000 |
| Subject: | note 104055 modified in function.date by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-179905@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.
<?php
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);
}
?>
--was--
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);
}
http://php.net/manual/en/function.date.php