当前位置: 动力学知识库 > 问答 > 编程问答 >

search - 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 :(

网友答案:

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'
网友答案:

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.

分享给朋友:
您可能感兴趣的文章:
随机阅读: