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 Formatting Dates For Reporting

John Grillo
John Grillo
30,241 Points

STRFTIME Task challenge

I'm doing the SQL reporting challenge and seem to be stuck on it. I've definitely done this before in my job, but for some reason I'm having a hard time with it. The challenge says that I'm formatting it to the correct time but after checking the SQL, MySQL and SQLite documentation, I can't seem to see what it is that I'm not getting.

Anyway, would appreciate a spot of advice.

SELECT
   title
  , STRFTIME("%M%Y", date_released) AS 'month_year_released'
FROM movies

3 Answers

John, you're very close. It makes a difference whether you use m or M. This works fine:

SELECT title, STRFTIME("%m/%Y", date_released) AS 'month_year_released' FROM movies
John Grillo
John Grillo
30,241 Points

Wait, let me check that... Well i'll be dipped! Class case of the off-by-one error. Or more appropriately...it's other 'm'!

I know, I know...it was obligatory.

Help ref. for SQLITE as per the video in question. BTW, the big M is for 'Minutes', not 'months'.

Fuzzyclaws Frostpaw
Fuzzyclaws Frostpaw
5,178 Points

http://php.net/strftime in the format parameters, it explains: %y Two digit representation of the year Example: 09 for 2009, 79 for 1979 %Y Four digit representation for the year Example: 2038

That's interesting. Why It doesn't matter if we use y instead of Y?