How retrieve next 30 days data from database? [closed]
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
开发者_如何学运维 Improve this questionPlease anyone can tell me the query to retrieve next 30 days data from database starting from today? Its a database users can upload upto next 90 days data.
SELECT * FROM table WHERE date >= CURRENT_TIMESTAMP AND date <= CURRENT_TIMESTAMP + INTERVAL 30 DAY
SELECT *
FROM table
WHERE date BETWEEN CURRENT_TIMESTAMP() AND DATE_ADD(CURRENT_TIMESTAMP(), INTERVAL 30 DAY)
Assuming you're storing your dates as integers (unix epoch) instead of timestamps you could do something like this:
SELECT * FROM wherever WHERE startdate >= UNIX_TIMESTAMP() AND startdate <= UNIX_TIMESTAMP() + 2592000;
This is assuming those 30 days consist of 2.592.000 seconds. Similar code is possible using the timestamps.
精彩评论