SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot annimal's Avatar
    Join Date
    May 2004
    Location
    london
    Posts
    115
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation Date Search Problem

    Hi all i have a D/B search querying two UNIX time stamps. like this
    PHP Code:
    $date=1150498800;
    $date2=1153782000
    $query="SELECT event,eventyear,eventstart,totalnt,totalg,ticketsleft,tadult,tchild FROM admin 
    WHERE stamp <= 
    $date2 AND stamp >= $date AND stamp AND event LIKE '%$superp%'"
    this works appart from the result i get is not correct!
    the result is -3 dates from $date2 i beleve i need some thing like this
    PHP Code:
    <= $date2 AND stamp >= <= $date AND stamp 
    but i cant figure out the correct syntax ive tryed using a BETWEEN query to but obviously that searchs between lol.
    thanks for any help
    Last edited by annimal; Jan 15, 2006 at 10:59. Reason: typo

  2. #2
    SitePoint Addict phpster's Avatar
    Join Date
    Feb 2005
    Location
    Toronto, Canada
    Posts
    374
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    WHERE stamp between $date and $date2 AND ...
    phpster

    I wish my computer would do what I want it to.
    Not what I tell it to do...

  3. #3
    SitePoint Zealot annimal's Avatar
    Join Date
    May 2004
    Location
    london
    Posts
    115
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the reply I cant use BETWEEN becouse it dose not include the equel to value
    I need
    stamp >$date AND stamp <$date2 but the format is not correct.
    PHP Code:
    $query="SELECT event,eventyear,eventstart,totalnt,totalg,ticketsleft,tadult,tchild FROM admin 
    WHERE stamp > 
    $date AND stamp < $date2 AND event LIKE '%$superp%'"
    That looks ok but it dosnt seem to work even if i use =
    PHP Code:
    stamp => $date AND stamp <= $date2 

  4. #4
    SitePoint Addict phpster's Avatar
    Join Date
    Feb 2005
    Location
    Toronto, Canada
    Posts
    374
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    between does ue the equal value

    add quotes, and may format the datestamp into something usable

    WHERE date_format(stamp,'%Y-%m-%d') between date_format('$date','%Y-%m-%d') and date_format('$date2','%Y-%m-%d') AND ...
    phpster

    I wish my computer would do what I want it to.
    Not what I tell it to do...

  5. #5
    SitePoint Zealot annimal's Avatar
    Join Date
    May 2004
    Location
    london
    Posts
    115
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    HMM ok im not quite getting this
    I have the date being submited to the database as
    Saturday June 17 2006

    I then format it like so
    PHP Code:
    $Date="Saturday June 17 2006";
    $stamp =strtotime("$Date"); 
    are you saying that i have to format the date like this
    PHP Code:
    $date =date('Y-%m-%d',$stamp); 
    before i can use a query to search the dates?

  6. #6
    SitePoint Zealot annimal's Avatar
    Join Date
    May 2004
    Location
    london
    Posts
    115
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    im still having no luck with this date search i get no errors but no data echoed ether
    ive change my script around but still i have no results
    PHP Code:
    $superp="Nativity Play";
    $month "Monday June 12 2003";
    $month2 " Thursday May 24 2007";
    $stamp1 strtotime("$month");
    $stamp2 strtotime("$month2"); 
    $datedate('Y-m-d'$stamp1);
    $date2 date('Y-m-d'$stamp2);
    include 
    "Co.php";    
    $conn mysql_connect("$location","$username","$password");     
    if (!
    $conn) die ("Could not connect MySQL");     
    mysql_select_db($database,$conn) or die ("Could not open database");    
    $query="SELECT eventyear,eventstart FROM session WHERE stamp BETWEEN $date AND $date2 AND event LIKE '%$superp%'"
    $res2 mysql_query($query) or die ("Error in query: $query. ".mysql_error()); 
    $row mysql_fetch_array($res2); 
    while( 
    $row mysql_fetch_assoc$res2 )){
    echo
    "Events between dates: $row[event]";} 
    thanks for any help


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •