MySQL SELECT last few days?

I played with MYSQL, and I know that there is a limit command that shows a certain amount of results, but I was wondering if only MySQL could only last 3 days or something like that. Just wondering.

Update: I used NOW () to store time.

+49
sql mysql
Nov 11 '09 at 4:41
source share
5 answers

Use date three days ago:

WHERE t.date >= DATE_ADD(CURDATE(), INTERVAL -3 DAY); 

Check the documentation for DATE_ADD .

Or you can use:

 WHERE t.date >= ( CURDATE() - INTERVAL 3 DAY ) 
+109
Nov 11 '09 at 6:13
source share

You can use this in your MySQL WHERE clause to return records created in the last 7 days / week:

created >= DATE_SUB(CURDATE(),INTERVAL 7 day)

Also use NOW () in subtraction to get hh: mm: ss resolution. Thus, to return records created exactly (to the second) in the last 24 hours, you can do:

created >= DATE_SUB(NOW(),INTERVAL 1 day)

+9
Apr 16 '14 at 5:37
source share

You can use a combination of the UNIX_TIMESTAMP () function for this.

 SELECT ... FROM ... WHERE UNIX_TIMESTAMP() - UNIX_TIMESTAMP(thefield) < 259200 
+2
Nov 11 '09 at 4:45
source share

WHERE t.date >= DATE_ADD(CURDATE(), INTERVAL '-3' DAY);

use quotes for value -3

-2
Mar 20 '14 at 1:24
source share
 SELECT DATEDIFF(NOW(),pickup_date) AS noofday FROM cir_order WHERE DATEDIFF(NOW(),pickup_date)>2; 

or

 SELECT * FROM cir_order WHERE cir_order.`cir_date` >= DATE_ADD( CURDATE(), INTERVAL -10 DAY ) 
-2
Jan 06 '15 at 11:26
source share



All Articles