otuatail Posted June 22, 2015 Share Posted June 22, 2015 Hi I have to show all records over selected periods Last 6 months 2015 2014 2013 Before 2013 The first is easy WHERE LastVisit > DATE_ADD(CURRDATE, INTERVAL -6 MONTH I am finding the others harder. If I have to extract the year it could be a slow query. Link to comment https://forums.phpfreaks.com/topic/296950-show-all-records-over-a-date-period/ Share on other sites More sharing options...
mac_gyver Posted June 22, 2015 Share Posted June 22, 2015 the WHERE clause would be - WHERE YEAR(LastVisit) = whatever_year_value_you_want i'm pretty sure this would have the same level of performance as your Last 6 months query. Link to comment https://forums.phpfreaks.com/topic/296950-show-all-records-over-a-date-period/#findComment-1514557 Share on other sites More sharing options...
Barand Posted June 22, 2015 Share Posted June 22, 2015 WHERE lastvisit BETWEEN '2015-01-01' AND '2015-12-31' would use the index (assuming there is one on the lastvisit column) and therefore much faster Link to comment https://forums.phpfreaks.com/topic/296950-show-all-records-over-a-date-period/#findComment-1514627 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.