Here is my problem, I want to fetch next 30 days records from the table. I have a field in my table. For ex: In my table I have resource_date
, In this column I have many records from 2013-02-05
to 2015-10-10
. Say, If I logged into the website today(Today's Date is- 16/01/2015
, It should fetch record for next 15 days and so on). How to do this? Thanks in advance
相关问题
- sqlyog export query result as csv
- NOT DISTINCT query in mySQL
- MySQL: conduct a basic search
- Why sometimes there is one of more gap(s) in the v
- mySQL alter table on update, current timestamp
In MySQL, you can use the
NOW()
function to get the currentDATETIME
, and theINTERVAL
keyword to get intervals of time.So, to get the records where
resource_date
is within the next 30 days, you would use:In practice, you should rarely use
SELECT *
, and you should consider adding aLIMIT
to this query to prevent your application from returning a result set that is "too large".One way to do it
Here is a SQLFiddle demo
http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html
Careful I think now() does minutes and hours so you miss a portion of a day.