MySQL date question

User avatar
Jezza
5StarLounger
Posts: 847
Joined: 24 Jan 2010, 06:35
Location: A Magic Forest in Deepest, Darkest, Kent

MySQL date question

Post by Jezza »

Firstly, my apologies as I know this is primarily a Microsoft area but wanted to know if, on the off chance, anyone can answer this conundrum I have.

I have a MySQL database table called Orders with a column order_date and some fictitious dates in 2008, and I have this code:

Code: Select all

SET @sDate = '2008-06-01';
SET @eDate = '2008-06-30';
SELECT * FROM Orders WHERE
order_date BETWEEN @sDate AND @eDate;
Which is basically showing orders in June 2008, and it works as expected. However, when I put in the @eDate to 2008-06-31 (Remembering June only has 30 days) it still works!!! But, if I put in @eDate to 2008-06-32 it fails as expected as no month has 32 days, so why does it work for 31 days?
I have tried it with similar results:

Code: Select all

SET @sDate = '2008-06-01';
SET @eDate = '2008-06-30';
SELECT * FROM Orders WHERE
order_date >= @sDate AND order_date <= @eDate;
There is always one bright spark in my lectures :scratch:
Jerry
I’ll be more enthusiastic about encouraging thinking outside the box when there’s evidence of any thinking going on inside it

User avatar
HansV
Administrator
Posts: 78439
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: MySQL date question

Post by HansV »

My very uninformed guess would be that day numbers up to and including 31 are always accepted for convenience since some months have 31 days, but 32 and higher are not accepted since there are no months with 32 days.
Best wishes,
Hans