Link to home
Start Free TrialLog in
Avatar of illuzian
illuzianFlag for Australia

asked on

MySQL Select * from TABLE Between DATE RANGE?

Hey Guys,

I would like to know how to structure and SQL query to query between months ranges

Something along the lines of:
SELECT * FROM table WHERE datetime BETWEEN xx/xx/xx AND xx/xx/xx

We have a table with the following date field entry named datetime:

20090208175726478

Which I am assuming is an entry for 2009 02 08 TIME SECONDS or something along those lines

I have read the MySQL Reference on "date" but couldn't make much sense of it - SQL isn't my strong point.

Thanks in advance.
Avatar of Umesh
Umesh
Flag of India image

Try this..
SELECT * FROM table WHERE STR_TO_DATE(`datetime`,'%Y%m%d%f') between '2009-02-01' AND '2009-02-28';
 
You can change the daterange 2009-02-01 and 2009-02-28... 

Open in new window

Avatar of illuzian

ASKER

Okay cheers for the reply but we are using mysql 3.23 so it looks like this is not an options

I have put together this query but it only works if I specify

= 'xxxx-xx-xx'

and not the between as shown bellow any ideas?
select * from saled where date_add(concat(SUBSTRING(`DATETIME` FROM 1 FOR 4),'-',SUBSTRING(`DATETIME` FROM 5 FOR 2),'-',SUBSTRING(`DATETIME` FROM 7 FOR 2)), interval 0 day) between '2008-03-01' and '2008-06-01';

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Umesh
Umesh
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Excellent answer for the query, I should of specified the version in the initial post as STR_TO_DATE was not available.