House of Fusion
Search over 2,500 ColdFusion resources here
  
Home of the ColdFusion Community

Mailing Lists
Home /  Groups /  SQL

date range in mySQL not working

  << Previous Post |  RSS |  Sort Oldest First |  Sort Latest First |  Subscribe to this Group Next >> 
Hello all.
Torrent Girl
02/11/11 11:46 A
>>BETWEEN '10/01/2010' AND '02/01/2011'
Claude_Schnéegans
02/11/11 11:54 A
Thanks all.
Torrent Girl
02/11/11 12:00 P
Try
Kelly
02/11/11 11:59 A
That didn't work either.
Torrent Girl
02/11/11 01:00 P
Date should be 'YYYYMMDD'. Leave out the dashes.
Raymond Thompson
02/11/11 01:08 P
Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Torrent Girl
02/11/2011 11:46 AM

Hello all. This simple query is not retrieving any records in mySQL: SELECT * FROM agentdaily where dateWorked BETWEEN '10/01/2010' AND '02/01/2011' The data type for dateWorked in varchar.

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Bryan Stevenson
02/11/2011 11:52 AM

I suspect the issue is that it is a varchar......thus "BETWEEN" is not processing the way you would expect a date to be processed If you think about it......what is between 2 strings......what falls between "cat" and "dog"? ;-) Can you change the data type for dateWorked? Cheers On Fri, 2011-02-11 at 11:38 -0500, Torrent Girl wrote: ----- Excess quoted text cut - see Original Post for more -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Claude_Schnéegans
02/11/2011 11:54 AM

>>BETWEEN '10/01/2010' AND '02/01/2011' >>The data type for dateWorked in varchar. You cannot use this date format in a text field if you need to sort it or compare ranges. You need to use at least some "yyyy mm dd" format or better a true date format in the database. In your example '10/01/2010' is alphabetically greater than  '02/01/2011' although it is chronologically before, and there cannot be nothing in between.

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Torrent Girl
02/11/2011 12:00 PM

Thanks all. I will change the data type and see if that helps

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Kelly
02/11/2011 11:59 AM

Try SELECT * FROM agentdaily where dateWorked BETWEEN '2010-10-01' AND '2011-02-01' On 2/11/2011 11:38 AM, Torrent Girl wrote: ----- Excess quoted text cut - see Original Post for more -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Raymond Thompson
02/11/2011 01:08 PM

Date should be 'YYYYMMDD'. Leave out the dashes. Ray Thompson Tau Beta Pi Headquarters 865-546-4578 www.tbp.org That didn't work either. >Try > >SELECT * FROM agentdaily where dateWorked BETWEEN '2010-10-01' AND '2011-02-01' > > > > >On 2/11/2011 11:38 AM, Torrent Girl wrote: >>

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Bryan Stevenson
02/11/2011 01:11 PM

Well that would only work IF your dates are stord in that format.....but even then it's a bit weak. The real solution is to change the dates to dates ;-) Cheers On Fri, 2011-02-11 at 12:52 -0500, Torrent Girl wrote: ----- Excess quoted text cut - see Original Post for more -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
George Gallen
02/15/2011 12:09 PM

Another solution that might work (leaving dateWorked as varchar) SELECT * FROM agentdaily where STR_TO_DATE(dateWorked,'%M/%d/%Y') BETWEEN .... As long as the date is in the format of mm/dd/yyyy that should convert the varchar output to a date format, and allow the Between to work correctly. Again, SHOULD.... Problem is if you changed the type from varchar to date, unless you reload the data, the data that is in the table will be in internal date format, and probably was being ignored. George ----- Excess quoted text cut - see Original Post for more -----


<< Previous Thread Today's Threads Next Thread >>

Search sql

May 26, 2013

<<   <   Today   >   >>
Su Mo Tu We Th Fr Sa
       1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31   

Designer, Developer and mobile workflow conference