Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mysql Query date >= 90 days

I want to query a database for records where the date is equal to, or greater than 90 days. This is what I have so far:

$format = 'Y-m-j G:i:s'; 

$date = date ( $format ); 

// -90 days from today 

date ( $format, strtotime ( '-90 day' . $date ) ); 

I'm just a bit unsure now how to structure the MYSQL query. Would it be something like this (I know this is wrong but i'm unsure as to what else to do):

"SELECT * FROM recurringPayments WHERE lastpmt >= date ( $format, strtotime ( '-90 day' . $date ) ) ";
like image 398
109221793 Avatar asked Oct 11 '10 12:10

109221793


2 Answers

<?php
mysql_query("SELECT * FROM recurringPayments WHERE lastpmt <= (NOW() - INTERVAL 90 DAY)");
?>
like image 187
ITroubs Avatar answered Sep 28 '22 06:09

ITroubs


<?php
$d = date ( $format, strtotime ( '-90 days' ) );

mysql_query("SELECT * FROM recurringPayments WHERE lastpmt <= '$d'");
?>

Assuming you want data 90 days and older.

like image 23
methodin Avatar answered Sep 28 '22 05:09

methodin