Forum Moderators: coopster
Something like...
$sql_query = "SELECT * FROM mytable WHERE dateAdded like 'todays date - 60 days'";
Excuse my simple questions... looks like I'm setting up camp in this forum whilst learning PHP/SQL etc.
dateAdded would need to be a date or date-and-time [mysql.com] column type. The following statement will return any rows where the dateAdded column is 60 days or more. Note that it will also return any rows where the dateAdded column has a zero value, such as 0000-00-00 or 0000-00-00 00:00:00.
SELECT * FROM mytable WHERE DATE_SUB [mysql.com](NOW() [mysql.com], INTERVAL 60 DAY) > dateAdded;
# If you don't want the zero values, specify so:
SELECT *
FROM mytable
WHERE dateAdded > 0
AND DATE_SUB(NOW(), INTERVAL 60 DAY) > dateAdded
;
# or you could use the TO_DAYS [mysql.com] function,
# which is a bit more intuitive than DATE_SUB:
SELECT * FROM mytable WHERE TO_DAYS(NOW()) - TO_DAYS(dateAdded) > 60;
dateAdded column has a zero value, such as 0000-00-00 or 0000-00-00 00:00:00.:
SELECT * FROM mytable WHERE DATEDIFF [mysql.com](NOW(), dateAdded) > 60;
# If you want the zero values, specify so:
SELECT *
FROM mytable
WHERE dateAdded = 0
OR DATEDIFF(NOW(), dateAdded) > 60
;