check db records for dates 11 months or older

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
bob_the _builder
Forum Contributor
Posts: 131
Joined: Sat Aug 28, 2004 12:25 am

check db records for dates 11 months or older

Post 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
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

What database are you using?
(#10850)
bob_the _builder
Forum Contributor
Posts: 131
Joined: Sat Aug 28, 2004 12:25 am

Post by bob_the _builder »

Ahh, good call

MYSQL

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


Thanks
bob_the _builder
Forum Contributor
Posts: 131
Joined: Sat Aug 28, 2004 12:25 am

Post 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
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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
bob_the _builder
Forum Contributor
Posts: 131
Joined: Sat Aug 28, 2004 12:25 am

Post by bob_the _builder »

Hi,

Seems to work great .. Thanks!
Post Reply