TheSky Posted June 12, 2011 Share Posted June 12, 2011 is there way to delete database rows what are like older then 30 days i have colum named today and i want like delete older then 30 days rows value is like 2011.06.12 thankyou for your time Link to comment https://forums.phpfreaks.com/topic/239136-little-mysql-help-pleas/ Share on other sites More sharing options...
The Little Guy Posted June 12, 2011 Share Posted June 12, 2011 step 1 (optional): backup your table step 2: Convert your date to a valid mysql date: update my_table replace(my_date_column, '.', '-'); step 3: Convert your date column to a date: alter table my_table change my_date_column my_date_column date not null step 4: add the code to delete dates older than 30 days: delete from my_table where my_date_column > date_sub(now(), interval 30 day); Link to comment https://forums.phpfreaks.com/topic/239136-little-mysql-help-pleas/#findComment-1228684 Share on other sites More sharing options...
TheSky Posted June 12, 2011 Author Share Posted June 12, 2011 SQL query: UPDATE u_statistics replace( today, '.', '-' ) MySQL said: Documentation #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'replace(today, '.', '-')' at line 1 am i doing somthing wrong ? Link to comment https://forums.phpfreaks.com/topic/239136-little-mysql-help-pleas/#findComment-1228704 Share on other sites More sharing options...
The Little Guy Posted June 12, 2011 Share Posted June 12, 2011 Oops, try this: UPDATE u_statistics set today = replace( today, '.', '-' ) Link to comment https://forums.phpfreaks.com/topic/239136-little-mysql-help-pleas/#findComment-1228707 Share on other sites More sharing options...
The Little Guy Posted June 12, 2011 Share Posted June 12, 2011 Don't forget when you insert into this table, you need to use this format: YYYY-MM-DD Link to comment https://forums.phpfreaks.com/topic/239136-little-mysql-help-pleas/#findComment-1228709 Share on other sites More sharing options...
TheSky Posted June 12, 2011 Author Share Posted June 12, 2011 delete from my_table where my_date_column > date_sub(now(), interval 30 day); :-\ it deleted all records not older then 30 days Link to comment https://forums.phpfreaks.com/topic/239136-little-mysql-help-pleas/#findComment-1228716 Share on other sites More sharing options...
The Little Guy Posted June 12, 2011 Share Posted June 12, 2011 okay, then just reverse: > to: < btw. I hope you backed up your table. Link to comment https://forums.phpfreaks.com/topic/239136-little-mysql-help-pleas/#findComment-1228718 Share on other sites More sharing options...
TheSky Posted June 12, 2011 Author Share Posted June 12, 2011 step 1 (optional): backup your table ok i will try Link to comment https://forums.phpfreaks.com/topic/239136-little-mysql-help-pleas/#findComment-1228720 Share on other sites More sharing options...
TheSky Posted June 12, 2011 Author Share Posted June 12, 2011 hmm it deletes now automaticaly ? i think it worked Link to comment https://forums.phpfreaks.com/topic/239136-little-mysql-help-pleas/#findComment-1228723 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.