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 trialTeacher Russell
16,873 PointsChecking for dates in a query.
Am I mistaken, or is it sometimes necessary, when running a query, to write the date "2017-04-20" and sometimes "2017-4-20"?
2 Answers
Steven Parker
231,184 PointsDate conversions are typically done with 2-digit months and days.
Have you seen anything in the courses where it was done differently?
Teacher Russell
16,873 PointsIn this practice video, the dates in the customer table were written with the single digit, which I didn't expect and didn't notice, as I had already developed the habit of writing it with 2. I can't remember the challenge, but as they were all very easy, I was probably going from memory and not actually looking at the table. The date was written out in the clue, and I was just looking at that. All dates were written 2017-4-20. Maybe someone had a too happy a 4-20:) Or maybe I shouldn't assume the date will be written any one way in a table.
Teacher Russell
16,873 PointsThanks for the help and info. I appreciate it.
Teacher Russell
16,873 PointsTeacher Russell
16,873 PointsI can't remember what I was on at that moment..a quiz between videos probably. I was stuck on one, and it turned out to be the date. It wanted it written with one digit for the month that one time. It may have been that short practice after the SQL beginners course. It was looking for 2017-4-20. It would not accept 04, which was what I originally typed.
Steven Parker
231,184 PointsSteven Parker
231,184 PointsThat seems rather unusual. Usually the style of your answer will be the preferred format. Certainly the date functions for SQLite (used in the courses) all work that way.
Steven Parker
231,184 PointsSteven Parker
231,184 PointsSQLite is a special case, as the fields are essentially type-less. But the functions provided for dates work with certain formats, and I believe they all use 2 digits for months.
Other databases usually have a dedicated format for dates, so the actual storage is independent from the format. And the format can be specified different ways using templates.