Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Databases Reporting with SQL Date and Time Functions Calculating Dates

How do I show next week in SQL, i,e. starting from coming Sunday to the following Saturday?

I would like to show blog posts scheduled next week. How do I get SQL consider that?

1 Answer

Andrew Wong
seal-mask
.a{fill-rule:evenodd;}techdegree
Andrew Wong
Full Stack JavaScript Techdegree Student 15,373 Points

Try using:

BETWEEN DATE("now") AND DATE("now", "+6 days");

So, if your table is titled "blogs" and the dates are in a column titled "scheduled_for"..

SELECT COUNT(*) FROM blogs WHERE scheduled_for BETWEEN DATE("now") AND DATE("now", "+6 days");

I want sql to automatically detect the date. Will this work:

SELECT COUNT(*) FROM blogs WHERE scheduled_for BETWEEN getdate() AND getdate("+6 days");