Select date range on mysql timestamp

Dar*_*ney 6 mysql sql

I am trying the following but get no results:

SELECT *
FROM users_test
WHERE dateadded >= UNIX_TIMESTAMP('2012-02-01 00:00:00') 
AND dateadded <  UNIX_TIMESTAMP('2012-11-01 00:00:00');
Run Code Online (Sandbox Code Playgroud)

Yet I know there are columns with dates within that range e.g.

2012-05-11 17:10:08
Run Code Online (Sandbox Code Playgroud)

Is there a better way to do this?

Eventually I want to search multiple parameters, albeit not at the same time, like today, yesterday, last week, last month etc and also a date range and month range

Dar*_*jax 13

你有没有尝试过?

SELECT *
FROM users_test
WHERE dateadded >= '2012-02-01 00:00:00'
AND dateadded <  '2012-11-01 00:00:00'
Run Code Online (Sandbox Code Playgroud)

对于我所看到的,似乎你的表以你想要的方式存储数据(2012-05-11 17:10:08),所以在这种情况下你不需要UNIX_TIMESTAMP.

此外,我可以看到你想从结果中排除第二个日期(因为你正在使用<而不是<=),否则使用WHERE dateadded BETWEEN '2012-02-01 00:00:00' AND '2012-11-01 00:00:00'也会很好......


RTB*_*RTB 5

只需使用SQL BETWEEN关键字.就这样.