JonathanAnon Posted December 15, 2006 Share Posted December 15, 2006 Hi I have a piece of SQL code to pull out records that are only one year old$sql= "SELECT * FROM projects WHERE DATE_SUB(CURDATE(),INTERVAL 365 DAY) <= '$currentdate';";But how do I get records that are older than one year ??I have tried the opposite sign but it will not work. regards, Jonathan. Quote Link to comment Share on other sites More sharing options...
a2bardeals Posted December 15, 2006 Share Posted December 15, 2006 i don't know your date format in SQL but if it's DATE and not TIMESTAMP then you could try something like:$oneyearago = date('Y-m-d', mktime(0, 0, 0, date('Y') - 1, date('m'), date('d')));$twoyearsago = date('Y-m-d', mktime(0, 0, 0, date('Y') - 2, date('m'), date('d'))); $sql= "SELECT * FROM projects WHERE DATE_SUB <= '$oneyearago' && DATE_SUB >=$twoyearsago' ;"; Quote Link to comment Share on other sites More sharing options...
fenway Posted December 16, 2006 Share Posted December 16, 2006 I don't understand -- just add a year to the desired date, and see if it's still not "now":e.g. WHERE CURDATE() > DATE_ADD( '$currentdate'. 365 DAY ) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.