开发者

MySQL SELECT last few days?

开发者 https://www.devze.com 2022-12-11 06:19 出处:网络
I was playing with MYSQL and I know there\'s a limit command that shows a certain amount of results, but i was wondering if MySQL alone can show only the la开发者_运维技巧st 3 days or something. Just

I was playing with MYSQL and I know there's a limit command that shows a certain amount of results, but i was wondering if MySQL alone can show only the la开发者_运维技巧st 3 days or something. Just wondering.

Update: I used NOW() to store times.


Use for a date three days ago:

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

Check the DATE_ADD documentation.

Or you can use:

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


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

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

Also use NOW() in the subtraction to give hh:mm:ss resolution. So to return records created exactly (to the second) within the last 24hrs, you could do:

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


You could use a combination of the UNIX_TIMESTAMP() function to do that.

SELECT ... FROM ... WHERE UNIX_TIMESTAMP() - UNIX_TIMESTAMP(thefield) < 259200


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 )


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

use quotes on the -3 value

0

精彩评论

暂无评论...
验证码 换一张
取 消