How do I delete where dateadded is 14 days old +

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
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

How do I delete where dateadded is 14 days old +

Post by simonmlewis »

Code: Select all

DELETE FROM samples WHERE status = 'added' AND DATEDIFF(now(),dateadded) > 14
Trying to run a little query that just deletes entries where the 'dateadded' is 14 days or more old.
This just deleted ALL that were "added", and only went in today.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: How do I delete where dateadded is 14 days old +

Post by Celauran »

Syntax looks correct and works as expected for me. dateadded is a DATE type column?
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: How do I delete where dateadded is 14 days old +

Post by simonmlewis »

Yes it is. "date" is in the field type.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: How do I delete where dateadded is 14 days old +

Post by simonmlewis »

Sorry my bad, it is working.
Thanks anyway.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
Post Reply