Maggie Ackermann
Maggie Ackermann

Reputation: 253

Specify PHP code to select dates and records 3 days old

I am trying to call data from SQL table that is only 3 days old

My table has a lbs-date column in it and is date format. I have tried the following but get no result from the query at all

 $result = mysql_query("SELECT *, DATE_FORMAT(datetime, '%y,%m,%d') FROM lbs_trace_etrack 
 WHERE lbs_date(datetime) = CURDATE() - INTERVAL 3 DAY 
 ORDER BY lbs_date DESC")

Is there any other way I can call only the last 3 days of information from the SQL my date format is Y/M/D

Upvotes: 0

Views: 167

Answers (2)

juergen d
juergen d

Reputation: 204746

SELECT *, DATE_FORMAT(lbs_date, '%y,%m,%d') 
FROM lbs_trace_etrack 
WHERE lbs_date >= CURDATE() - INTERVAL 3 DAY 
ORDER BY lbs_date DESC

Upvotes: 2

Nishu Tayal
Nishu Tayal

Reputation: 20830

check DATE_FORMAT. Its syntax is DATE_FORMAT(<date>,format) . Use like this :

SELECT *, DATE_FORMAT(lbs_date , '%y,%m,%d') FROM lbs_trace_etrack 
WHERE lbs_date = CURDATE() - INTERVAL 3 DAY 
ORDER BY lbs_date DESC

Upvotes: 0

Related Questions