tags:

views:

26

answers:

3

I need to retrieve data from within a specific date range.Anybody can help me to create a query to getting the information within date range 12-12-2009 to 12-15-2009 from a mysql table.(including 12 and 15)

A: 
SELECT ... WHERE DATEDIFF('2009-12-15',yourdatefield) <= 3 ...
wsh
+2  A: 

SELECT * FROM foo WHERE timestamp BETWEEN "2009-12-12" AND "2009-12-15"

kurige
Although, on second thought, I'm not sure if this would select 12 and 15 or not. It would be nice if it did, since this is pretty much the most *elegant* way to select date ranges. It just goes downhill from here.
kurige
A: 

Use this function in php first

function ChangeDateforDB($inputdate) {
  if($inputdate>0) {
    $month  = substr($inputdate,0,2);
    $date = substr($inputdate,3,2);
    $year  = substr($inputdate,6,4);
    $show = $year."-".$month."-".$date;
    return $show;
  }
}

After that you can use this in query like this in the checking condition,

checkdate >= '".ChangeDateforDB($fromdate)."' and checkdate <= '".ChangeDateforDB($todate)."'

Check this one, you can get the correct answer.

Karthik