Pihu Chadda
Pihu Chadda

Reputation: 1

{date} function help. Fetch record from mysql of specific dates

I need a help. This code help us when we put specific dates in box.

But if we want records of last 10days then what should we need to do. Automatic records of last 10 days

$sql = "select * from pub_website where  user='$user' &&  STR_TO_DATE(pdate,'%Y-%m-%d') = '$fromdate' && website='$site'";

Upvotes: 0

Views: 33

Answers (1)

Redbeard011010
Redbeard011010

Reputation: 964

To select all records within a certain date range:

SELECT * FROM pub_website WHERE pdate BETWEEN "2015-12-01 00:00:00" AND NOW()

To do this dynamically, so to speak, for the last 10 days:

SELECT * FROM pub_website WHERE pdate BETWEEN DATE_SUB(NOW(), INTERVAL 10 DAY) AND NOW();

Upvotes: 1

Related Questions