Martijn Mellens
Martijn Mellens

Reputation: 555

Simple searching on data in MYSQL

i'm having some troubles getting results by searching on date.

here's the format:

2006-03-25 23:27:12

if i'm searching i tried to use this:

select * from aol where QueryTime BETWEEN '2006-03-19 00:00:00' and '2006-03-18 00:00:00'

But i'm never getting any results :(

Upvotes: 1

Views: 61

Answers (2)

John Kane
John Kane

Reputation: 4443

You could look at the difference between the two dates:

SELECT DATEDIFF('2007-12-31 23:59:59','2007-12-30');

Or this may work as well.

SELECT something FROM tbl_name
-> WHERE DATE_SUB(CURDATE(),INTERVAL 30 DAY) <= date_col;

Both of these examples came from this page. They show a lot of different ways that you could do this.

Upvotes: 0

Nicola Cossu
Nicola Cossu

Reputation: 56357

Between requires lower value before and after greatest value of the range, otherwise it returns an empty resultset without any error.

select * from aol where QueryTime BETWEEN '2006-03-18 00:00:00' and '2006-03-19 00:00:00'

is the same of writing

select * from aol where QueryTime >= '2006-03-18 00:00:00' and QueryTime <= '2006-03-19 00:00:00'

Upvotes: 3

Related Questions