Getting records between dates depending on current date?!?

Discussion in 'PHP' started by jmansa, Jun 13, 2009.

  1. #1
    How can I get records from db between a start date and a end date depending on the cirrent date?"!?!
    $currentdate = date('Y-m-d G:i:s');
    
    $gasea="SELECT * FROM ".$prefix."_seasons WHERE start >= '$currentdate' AND end <= '$currentdate'";
    	$result = mysql_query($gasea);
    	$gasearow = mysql_fetch_array($result);
    	
    	$gaseason = $gasearow['seasonid'];
    PHP:
    This doesnt get an output?!?1 Please help :)
     
    jmansa, Jun 13, 2009 IP
  2. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #2
    What MySQL formats are start & end?

    Instead of using PHP to get the current date, try using NOW() instead:

    
    $gasea="SELECT * FROM ".$prefix."_seasons WHERE start >= NOW() AND end <= NOW()";
    
    PHP:
    Peace,
     
    Barti1987, Jun 13, 2009 IP
  3. jmansa

    jmansa Peon

    Messages:
    36
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    That didn't do the trick... My records in DB is stored as "DATE/TIME"... Any other idea?
     
    jmansa, Jun 14, 2009 IP
  4. matt_fawcett

    matt_fawcett Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    That will only get records that are time stamped with the exact date and time of now to the exact second so its likely that you won't find any rows for this exact second. If you wanted all records today you will need to search from the start of the day eg '2009-06-15 00:00:00' and '2009-06-15 23:59:59'
     
    matt_fawcett, Jun 15, 2009 IP