I’ve copied this code from another site [url]http://www.charles-reace.com/PHP_and_MySQL/Time_Difference/
What I wanted was that, say I had two databases, one called newproducts
and the other called just products
if the data in newproducts’s time difference is less than two months it would stay inside the newproducts, if not it would delete the entry and place it just into the products database.
What would I have to change in these two scripts to do it?
<?php
/**
* array timeDiff(int $t1, int $t2)
* returns array broken down into years/months/weeks/etc.
function timeDiff($t1, $t2)
{
if($t1 > $t2)
{
$time1 = $t2;
$time2 = $t1;
}
else
{
$time1 = $t1;
$time2 = $t2;
}
$diff = array(
‘years’ => 0,
‘months’ => 0,
‘weeks’ => 0,
‘days’ => 0,
‘hours’ => 0,
‘minutes’ => 0,
‘seconds’ =>0
);
foreach(array(‘years’,’months’,’weeks’,’days’,’hours’,’minutes’,’seconds’)
as $unit)
{
while(TRUE)
{
$next = strtotime(“+1 $unit”, $time1);
if($next < $time2)
{
$time1 = $next;
$diff[$unit]++;
}
else
{
break;
}
}
}
return($diff);
}
?>
<?php
$start = strtotime(‘2007-01-15 07:35:55’);
$end = strtotime(‘2009-11-09 13:01:00’);
$diff = timeDiff($start, $end);
$output = “The difference is:”;
foreach($diff as $unit => $value)
{
echo ” $value $unit,”;
}
$output = trim($output, ‘,’);
echo $output;
?>