i would like to select * from table where dates between (some_date and another_date)
the problem is that the dates are stored as varchar
!
here are examples of dates that i have:
7/29/2010 9:53 AM
7/16/2010 7:57:39 AM
please notice that some records have seconds and some do not
i dont care about the time at all i just need the date
reporttime
is the date
field
this is not working:
SELECT * FROM batchinfo
where cast(reporttime as date) between ('7/28/10' and '7/29/10')
this:
SELECT * from batchinfo WHERE reporttime BETWEEN STR_TO_DATE(7/28/2010, '%m/%/d/%Y %h:%i:%s %p')
AND STR_TO_DATE(7/29/2010, '%m/%/d/%Y %h:%i:%s %p')
is returning:
Truncated incorrect datetime value: '7/8/2010 11:47 AM'
Incorrect datetime value: '0.00012009' for function str_to_date
this:
SELECT * from batchinfo WHERE STR_TO_DATE(reporttime, '%m/%/d/%Y %h:%i:%s %p') BETWEEN STR_TO_DATE(7/28/2010, '%m/%/d/%Y')
AND STR_TO_DATE(7/29/2010, '%m/%/d/%Y')
is returning:
Incorrect datetime value: '7/8/2010 11:47 AM' for function str_to_date
OMG PONIES:
i am taking everything before the first blank:
SELECT * from batchinfo WHERE STR_TO_DATE(LEFT(reporttime,LOCATE(' ',reporttime)), '%m/%/d/%Y') BETWEEN STR_TO_DATE(7/28/2010, '%m/%/d/%Y')
AND STR_TO_DATE(7/29/2010, '%m/%/d/%Y')
and now i get this returned:
Incorrect datetime value: '7/8/2010' for function str_to_date
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…