Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cron Job

Status
Not open for further replies.

patrickstrijdonck

Programmer
Jan 18, 2009
97
NL
Hello all,

I want to make a cron job, that selects all records from a table, Looks if the Date is longer then 23 months ago (ex. Record 1 = date; 16-4-2009 | Record 2 = date; 16-4-2004, Cronjob must select record 2 (and all other records with a date longer then 23 months) and update a field in all records)

I dont know how to do that, but what i have for the update field part, is this

Code:
$now = date("Y-m-d");

if ( $cursustijd == "0000-00-00" ) {
	
?>
    <span class="style3">Outdated!</span><br>
<? 
} else {

// USAGE OF DateComp: 
$sDBDate = '2007-10-15 23:16:28'; 
$sCurrDate = gmdate('Y-m-d'); 
if (DateComp($cursustijd, $sCurrDate, '- 100 weeks')) { 
?>
    <span class="style3">Outdated!</span><br>
<?  
} else { 
?>
<span class="style4">Updated!</span><br>
<? 
} 
 
}}
?>

If someone would help me with this, would be great.

Ty in advance
 
Hi

Code:
$conn=pg_pconnect($connection_string);

$sql="update thetable set thefield='outdated' where datefield<now()-interval '3 week'";

pg_query($conn,$sql);
The above example works with PostgreSQL database. You specified no such requirement, so I suppose PostgreSQL is also fine for you.

Feherke.
 
Hi

The SQL [tt]update[/tt] should work with a minor modification : remove the single quotes ( ' ) around the [tt]interval[/tt] parameter :
Code:
$conn=mysql_connect($hostname,$username,$password);
mysql_select_db($database,$conn);

$sql="update thetable set thefield='outdated' where datefield<now()-interval 23 month";

mysql_query($sql,$conn);


Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top