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 SQL Basics Finding the Data You Want Searching Tables with 'WHERE'

Magnus Rydberg
Magnus Rydberg
4,683 Points

Why do we use quotes for the Date datatype in SQL?

I am curious about the Date datatype in and why it needs quotes in SQL. If enter a date where year month and day are separated with a hyphen I guess the entry could be read as one single block of information. With quotes the date looks as though it is a string.

1 Answer

Steven Parker
Steven Parker
231,248 Points

But without quotes it looks like math. 2016-02-28 would become 1986!

So by using strings, and having dates implicitly convert from strings, you get to represent dates in a readable form. In fact, there are optional methods you can use to convert to/from a wide variety of (string) formats.

There actually is a numeric date format, but it's one really big number and not very convenient to use.

Magnus Rydberg
Magnus Rydberg
4,683 Points

Hello Steven and thanks for your reply.

That makes sense. So without quotes 2016-02-28 would be interpreted as a calculation. The quotes protects that from happening. The string itself can, depending on the datatype defined for the column, then be converted to a date.