Need a sql command to delete records under a given time frame.

I need a sql command line to delete any records that are older than 30 minutes everytime a php page is loaded ...

<?PHP $sql="DELETE FROM prodcen_telcrm WHERE last_updated...."

Last updated field is as follows:
YYYY-MM-DD 24:59:59
ISO 8601

Thanks Experts !!
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ray PaseurCommented:
$my_time = date('c', strtotime('Now - 30 minutes'));
$sql="DELETE FROM prodcen_telcrm WHERE last_updated < '$my_time'";

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Or the MySQL equivalent

$sql="DELETE FROM prodcen_telcrm WHERE last_updated < adddate(curdate(), interval 30 minute)";
Ray PaseurCommented:
@Imaginx:  cyberkiwi and I often think alike.  Our assumption here is that you have defined this column as a DATETIME field.  If that is not the case, please post back here and we will suggest how to use ALTER TABLE to add a DATETIME column so you can use the familiar and effective code constructs.  This article may be helpful to you.
ImaginxAuthor Commented:
You guys both have helped me in the past, and here you are to help again. Hope you enjoyed your holidays.

Ray, the function you wrote was what I was looking to achieve.

Cyberkiwi, the query you wrote was exactly what I was looking to learn - I'm a little more familiar with PHP, but I knew that mysql was capable of such a task as well.

The two of you are great assets to this community. Thank you.
ImaginxAuthor Commented:
@cyberkiwi - seems that the sql command deletes records over 24 hours or 1 day & 30 minutes .. ??
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.