Jump to content

Recommended Posts

I have run into an issue that I have not been able to find any information about by searching either Google or these forums. I have been running this query for over a year now, with no problem. It simply counts records between two dates. Today, while refactoring the code on the same server, but using a fresh (non-production) database (in PHP), I noticed that none of my counts against this particular table were working correctly anymore. The thing is, Running my original query via PHP yields correct results. Running my original or query from a command line, I get the following:

 

mysql> SELECT COUNT(referral_id) FROM tbl_referral_info WHERE pt = 1 AND refDate BETWEEN 2010-01-11 and 2011-01-11;
+--------------------+
| COUNT(referral_id) |
+--------------------+
|                  0 |
+--------------------+
1 row in set, 2 warnings (0.00 sec)

mysql> show warnings;
+---------+------+------------------------------------------------------------+
| Level   | Code | Message                                                    |
+---------+------+------------------------------------------------------------+
| Warning | 1292 | Incorrect date value: '1998' for column 'refDate' at row 1 |
| Warning | 1292 | Incorrect date value: '1999' for column 'refDate' at row 1 |
+---------+------+------------------------------------------------------------+
2 rows in set (0.00 sec)

mysql>

 

All of the information that I have found through Google and these forums, only references Inserts and Updates not working due to incorrect date values. How is it that a Select is not working?  I have attempted to find the records with the incorrect date value, but can find nothing out of the ordinary. What am I missing here?

 

EDIT: (forgot to give additional info)

 

`refDate` date DEFAULT NULL

`pt` tinyint(1) DEFAULT '0'

 

mysql  Ver 14.14 Distrib 5.1.37

 

 

 

Thanks in advance,

Matt

 

Link to comment
https://forums.phpfreaks.com/topic/224127-help-with-incorrect-date-values/
Share on other sites

Put your dates in quotes:

 

mysql> SELECT COUNT(referral_id) FROM tbl_referral_info WHERE pt = 1 AND refDate BETWEEN '2010-01-11' and '2011-01-11';

 

Otherwise it will evaluate 2010 minus 1 minus 11 which is why it's giving 1998/1999 as the non-dates.

WOW. That does it. It is always something obvious that I just overlook. The bad part is, my production code has quotes around it, and even comparing the production code with what I was working on for refactoring, I still missed it!

 

Thanks for the help.

 

Matt

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.