Page 1 of 1

check db records for dates 11 months or older

Posted: Mon Oct 09, 2006 11:09 pm
by bob_the _builder
Hi,

I have a table that holds a date field, I am wanting to have a script that checks the table for dates that are more than 11 months old, and have it email the data of any matching records.

This will run as a cron job.

I not sure where to start on checking the date field for dates older than 11 months .. any help would be appreciated.


Thanks

Posted: Mon Oct 09, 2006 11:16 pm
by Christopher
What database are you using?

Posted: Mon Oct 09, 2006 11:40 pm
by bob_the _builder
Ahh, good call

MYSQL

I know its a query .. but not sure on the 11 months has passed part.


Thanks

Posted: Tue Oct 10, 2006 1:00 am
by bob_the _builder
Is it something like:

Code: Select all

$sql = mysql_query("SELECT * FROM table WHERE datefield(curdate(), INTERVAL 11 MONTH)");

I see example using:

Code: Select all

date_sub(curdate(), INTERVAL 11 MONTH)
Im assume date_sub is replaced with the field you are quering from the database?


Thanks

Posted: Tue Oct 10, 2006 3:08 am
by volka
datefield(curdate(), INTERVAL 11 MONTH)");
That would mean: there's a function datefield and it takes two parameters, a date and ....what is interval 11 month ;)

Code: Select all

SELECT
	*
FROM
	tablename
WHERE
	datefield <= curdate() - Interval 11 Month

Posted: Tue Oct 10, 2006 4:40 pm
by bob_the _builder
Hi,

Seems to work great .. Thanks!