I have the array of dates below
array(5) {
[0]=> string(19) \"2012-06-11 08:30:49\"
[1]=> string(19) \"2012-06-07 08:03:54\"
[2]=> st
Thats my variant. It works with date in future.
$Dates = array(
"2012-06-11 08:30:49",
"2012-06-07 08:03:54",
"2012-05-26 23:04:04",
"2012-05-27 08:30:00",
"2012-06-08 08:30:55",
"2012-06-12 07:45:45"
);
$CloseDate = array();
$TimeNow = time();
foreach ($Dates as $Date) {
$DateToCompare = strtotime($Date);
$Diff = $TimeNow - $DateToCompare;
if ($Diff < 0) $Diff *= -1;
if (count($CloseDate) == 0) {
$CloseDate['Date'] = $Date;
$CloseDate['Diff'] = $Diff;
continue;
}
if ($Diff < $CloseDate['Diff']) {
$CloseDate['Date'] = $Date;
$CloseDate['Diff'] = $Diff;
}
}
var_dump($CloseDate);