EchoFool Posted August 28, 2009 Share Posted August 28, 2009 Hey, I need help on how i would get a query to delete rows of data where by field 1 or field 2 (timestamp format) is set to a timestamp of 2 days or older and delete them. My current method is to loop all rows but thats not wise with more rows added so i need a new method. The timestamp format is: YYYY-MM-DD HH:MM:SS Hope you can help me. Link to comment https://forums.phpfreaks.com/topic/172336-delete-after-2-days/ Share on other sites More sharing options...
Maq Posted August 28, 2009 Share Posted August 28, 2009 You can accomplish this with DATE_SUB(). Link to comment https://forums.phpfreaks.com/topic/172336-delete-after-2-days/#findComment-908647 Share on other sites More sharing options...
EchoFool Posted August 28, 2009 Author Share Posted August 28, 2009 So: DELETE FROM table WHERE DATE_SUB(Field, NOW()) > 1; Would that compare the field to now as how many days has passed from the timestamp in the database? Link to comment https://forums.phpfreaks.com/topic/172336-delete-after-2-days/#findComment-908654 Share on other sites More sharing options...
Maq Posted August 31, 2009 Share Posted August 31, 2009 Something like this: DELETE FROM table WHERE field Any record where 'field' is more than 2 days old will be deleted. Link to comment https://forums.phpfreaks.com/topic/172336-delete-after-2-days/#findComment-909688 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.