June 20th, 2000, 12:26 PM
I'm trying to search a range of dates on a sql server using PHP. Giving it one date and it will look for something X many days before and after that particular date. The problem i'm running into is the fact that the sql server reads dates like yyyy-mm-dd and php does it mm-dd-yyyy. I'm trying to use the sql commands to search for the date, but the problem i'm having with that is my dates have dashes while if i use the add_date() or sub_date() function the input don't use dashes. take a look
$sql="SELECT * FROM search_data WHERE date_sub($date,interval $number_of_days day) < $date AND date_add($date,interval $number_of_days day) >= $date ORDER BY file_name";
June 20th, 2000, 01:39 PM
First of all most sql servers allow you to change the date format. I'd check the documentation for your database and try to get it to match the way your are dealing with dates in php. I use Microsoft SQL and I find it much easier to work using php's time functions. Then, when the time comes to run a query against the database, I simply convert the time function to a date that sql recognizes...
$sql = "SELECT * FROM product_detail WHERE product_date_added > " . date("M d Y", $start_time);
Ulysses J Ludwig