Link to home
Create AccountLog in
Avatar of Imaginx
Imaginx

asked on

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 !!
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
SOLUTION
Avatar of cyberkiwi
cyberkiwi
Flag of New Zealand image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
@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. https://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_201-Handling-date-and-time-in-PHP-and-MySQL.html
Avatar of Imaginx
Imaginx

ASKER

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.
Avatar of Imaginx

ASKER

@cyberkiwi - seems that the sql command deletes records over 24 hours or 1 day & 30 minutes .. ??