tendrousbeastie Posted May 22, 2008 Share Posted May 22, 2008 Hi all, This may be a really obvious question, but I had a search and couldn't find an answer to it. Apologies if its answered elsewhere. I need to be able to run an SQL query on my MySQL DB that is essentially like the code below: SELECT fields FROM table WHERE date > now()-12months Hopefully my intention is obvious, - I want to return all result from the table where the column date contains a datetime of within the last months (or xx months preferably). Does anyone know the syntax or commands necessary to do this? Quote Link to comment https://forums.phpfreaks.com/topic/106828-comparing-a-given-datetime-to-this-time-x-months-ago/ Share on other sites More sharing options...
Barand Posted May 22, 2008 Share Posted May 22, 2008 SELECT fields FROM table WHERE date > now() - INTERVAL 12 MONTH Quote Link to comment https://forums.phpfreaks.com/topic/106828-comparing-a-given-datetime-to-this-time-x-months-ago/#findComment-547721 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.