Hi, i have made a form in which people fill out their details and its gets saved in database with

$today = date("F j, Y");

now i want to make a search for that forms with date , like Search with in last 3 days or Last 6 months. so when somebody do that, search will show all the forms submitted in last 3 days only or 6 months. respectively. please if somebody can write a code or example for that, instead of just telling me to use some function with just referring function's name.am just a amature in this.

Thank you in Advance

Recommended Answers

Read the available Date/Time functions in the manual:
http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_curdate

SELECT * FROM TABLE WHERE dateField > DATE_SUB(CURDATE(), INTERVAL 3 DAYS)

SELECT * FROM TABLE WHERE dateField > DATE_SUB(CURDATE(), INTERVAL 6 MONTHS)
Jump to Post

All 3 Replies

First off,

$sevendaysago = date("Y-m-d", mktime (0,0,0,date("m"),(date("d")-7),date("Y")));   // 2010-11-13

$tomorrow = date("Y-m-d", mktime (0,0,0,date("m"),(date("d")+1),date("Y")));  // 2010-11-21

i am using the following query, assumming that the dateformat is the same as the above variables.

$query = "SELECT * FROM table WHERE date BETWEEN '$sevendaysago' AND '$tomorrow'  ORDER BY date ASC";

First off,

$sevendaysago = date("Y-m-d", mktime (0,0,0,date("m"),(date("d")-7),date("Y")));   // 2010-11-13

$tomorrow = date("Y-m-d", mktime (0,0,0,date("m"),(date("d")+1),date("Y")));  // 2010-11-21

i am using the following query, assumming that the dateformat is the same as the above variables.

$query = "SELECT * FROM table WHERE date BETWEEN '$sevendaysago' AND '$tomorrow'  ORDER BY date ASC";

It worked, thanks Frankey. thanks a ton

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.