PDA

View Full Version : last updated


edbr
11-17-2006, 08:11 AM
On a site of mine, records are returned from a database (mysql/php) I would like them to show NEW for a period of say 7 days.
also the page shows a date of last update which at present i add manually.
Can these be added dynamically? If so can you point me in the ight direction?

davidj
11-17-2006, 09:10 AM
On a site of mine, records are returned from a database (mysql/php) I would like them to show NEW for a period of say 7 days.

ok i take it you have a date of input in your db

when you call this function just pass in your 2 dates

example...function call..passing in 2 dates

echo datediff('01/01/2006', '10/10/2006');

example... function...


function datediff($date1, $date2){

$ex1 = explode('/', $date1); // explode using / as delimiter into array
$ex2 = explode('/', $date2); // explode using / as delimiter into array

$mkTime1 = mktime(0,0,0,$ex1[1],$ex1[0],$ex1[2]); // convert to unix timestamp
$mkTime2 = mktime(0,0,0,$ex2[1],$ex2[0],$ex2[2]); // convert to unix timestamp

$difference = ($mkTime2 - $mkTime1 ) / 86400;

return $difference; // calculate and return
}


all you have to now is where you have the function call..


IF(datediff('01/01/2006', '10/10/2006') == 7)
{
/////////////////////////////////////////////////////
/// ******* do this bit of code *********///
/////////////////////////////////////////////////////
}


also the page shows a date of last update which at present i add manually.
Can these be added dynamically? If so can you point me in the ight direction?

in the insert SQL statement that you add the date manually you can use the CURDATE function...

INSERT INTO table1 (field1, filed2, field3, datefield) values ($fld1, fld2, $fld3, curdate);

edbr
11-17-2006, 09:34 AM
gulp. There goes the weekend. Thanks I will try to get to grips with this