Thread: Date Search

    #1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    1
    Rep Power
    0
    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";


    Any suggestions?
    thanks
    ryan
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Posts
    63
    Rep Power
    15
    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...
    like so

    $sql = "SELECT * FROM product_detail WHERE product_date_added > " . date("M d Y", $start_time);

    ------------------
    ----------------------
    Ulysses J Ludwig
    Consultant
    Ujludwig@yahoo.com
    310.678.8324

Similar Threads

  1. Frames hijacked after remote search
    By Telejoke in forum Antivirus Protection
    Replies: 2
    Last Post: September 26th, 2007, 10:32 AM
  2. search DB by date range
    By Simm in forum PHP Development
    Replies: 1
    Last Post: February 4th, 2004, 02:35 PM
  3. database date selection problem
    By kidsleep in forum MySQL Help
    Replies: 0
    Last Post: January 31st, 2004, 11:50 AM
  4. Is there any alternative to fulltext search?
    By irishairpics in forum MySQL Help
    Replies: 2
    Last Post: December 10th, 2003, 03:40 PM
  5. mySQL date messing with my searches
    By SuperFunHAppyGy in forum MySQL Help
    Replies: 0
    Last Post: December 5th, 2003, 02:31 PM

IMN logo majestic logo threadwatch logo seochat tools logo