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. Link to comment https://forums.phpfreaks.com/topic/30702-dates-older-than-one-year-old/ 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' ;"; Link to comment https://forums.phpfreaks.com/topic/30702-dates-older-than-one-year-old/#findComment-141501 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 ) Link to comment https://forums.phpfreaks.com/topic/30702-dates-older-than-one-year-old/#findComment-142119 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.