Select date range in timestamp mysql

I am trying to do the following but not getting any 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'); 

But I know that there are columns with dates within this range, for example.

 2012-05-11 17:10:08 

Is there a better way to do this?

In the end, I want to look for several parameters, although not at the same time, for example, today, yesterday, last week, last month, etc., as well as a date range and a range of months

+6
source share
4 answers

You tried?

 SELECT * FROM users_test WHERE dateadded >= '2012-02-01 00:00:00' AND dateadded < '2012-11-01 00:00:00' 

For what I see, it seems that your table stores data the same way you want to look for it ( 2012-05-11 17:10:08 ), so in this case you will not need UNIX_TIMESTAMP.

I also see that you want to exclude the 2nd date from the results (because you use < instead of <= ), otherwise use WHERE dateadded BETWEEN '2012-02-01 00:00:00' AND '2012-11-01 00:00:00' will also be wonderful ...

+13
source

Just use the SQL keyword BETWEEN . All this.

+4
source

try the following:

 SELECT * FROM users_test WHERE dateadded BETWEEN '2012-02-01 00:00:00' AND '2012-11-01 00:00:00' 
+3
source
 SELECT * FROM table_name WHERE DATE(date_field) between '2015-05-10' and '2015-05-21` 
0
source

All Articles