简体   繁体   中英

sql/php return rows that are older than 2 weeks

So after 3 hours of sleeping and going through every single article/question there is for this but I simply couldn't get it to work. My date column is in Ymd format, what I'm trying to get is all the rows that are past 2 weeks of the date available which is stated in the table.

This is the closest I've gotten it, but it doesn't return all of the rows still.

$date = date('Y-m-d',time()+(14*86400));
SELECT * FROM table_claims WHERE date_available > '$date'

An solution to this would make my day so much easier, thanks!

Using

$date = date('Y-m-d',time()-(14*86400));

will generate a $date for two weeks ago.

Also you can use a MYSQL function in the SQL query :

SELECT * FROM table_claims WHERE date_available < DATE_ADD(CURDATE(),INTERVAL -2 WEEK)

hey @Ale if you want to get past time(weeks, minutes, seconds) like in your case you want weeks, so you can use the format => strtotime("- 2 weeks/- 1 minutes") etc it will give you that timestamp

Now In your case try below one:

<?php
     $date = date("Y-m-d", strtotime("- 2 weeks"));
     SELECT * FROM table_claims WHERE date_available < '$date'
?>

It will give all the date_available smaller than two week or you can change your logic according to you (y)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM