Databases Reporting with SQL Date and Time Functions Formatting Dates For Reporting

John Grillo
John Grillo
30,215 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,215 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
4,121 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?