carlfaulkner Posted September 5, 2011 Share Posted September 5, 2011 I have a field timeStamp within my table which is type timestamp with a format 2011-09-30 23:11:12.The attribute is on update current_timestamp.can i run an sql command to select all rows that are older than 7 days from date when command is executed.something like select * from tbl where timeStamp < current_timestamp - 30 Link to comment Share on other sites More sharing options...
justsomeguy Posted September 5, 2011 Share Posted September 5, 2011 You can use date_sub to subtract 2 dates.http://dev.mysql.com/doc/refman/5.1/en/dat...nction_date-add Link to comment Share on other sites More sharing options...
carlfaulkner Posted September 5, 2011 Author Share Posted September 5, 2011 r u able to write an sql statement that would do this... Link to comment Share on other sites More sharing options...
justsomeguy Posted September 5, 2011 Share Posted September 5, 2011 Yes I am, are you? If not, I'll help you out. Start with the examples on that page in the manual. Link to comment Share on other sites More sharing options...
carlfaulkner Posted September 5, 2011 Author Share Posted September 5, 2011 i apoligise...took a while looking at the above link but i've got it. Thank you. Link to comment Share on other sites More sharing options...
carlfaulkner Posted September 5, 2011 Author Share Posted September 5, 2011 i apoligise...took a while looking at the above link but i've got it. Thank you.SELECT *FROM tblWHERE DATE_SUB( CURDATE( ) , INTERVAL 5DAY ) >= timeStamphow could i do the above but set a variable such as $expiry = "5" and replace INTERVAL 5 with INTERVAL $expiry. would that work. Link to comment Share on other sites More sharing options...
justsomeguy Posted September 5, 2011 Share Posted September 5, 2011 If you're using PHP, just use the variable in the query string. Check here for examples of using variables in strings:http://www.php.net/manual/en/language.type....string.parsing Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.