SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Sep 2007
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help with php/MySQL query?

    Hello,

    I'm trying to pull records from a MySQL database using a sql query - to pull records where the "exp_date" field is greater than or equal to today. How do I do this?

    Here is my query:

    Code PHP:
    $query = "SELECT v_title,link_id,v_descr,hw_added,hw_region_id,approved,user_approved,exp_date FROM ec3_ad WHERE hw_feat=1 AND approved=1 AND user_approved=1 AND hw_region_id=103 AND exp_date>=strftime('%d %b %Y %H:%M:%S') ORDER BY hw_added DESC LIMIT 20";

    ... but this is obviously not working because I don't know how to add today's date/time dynamically to the query.

    Any help would be great!

  2. #2
    SitePoint Guru
    Join Date
    Jan 2004
    Location
    Uppsala, sverige
    Posts
    700
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    Code:
    exp_date >= current_date

  3. #3
    SitePoint Enthusiast
    Join Date
    Aug 2007
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can use the function CURDATE(). The following query (reformatted)
    should work:

    PHP Code:
    SELECT 
        v_title
    ,
        
    link_id,
        
    v_descr,
        
    hw_added,
        
    hw_region_id,
        
    approved,
        
    user_approved,
        
    exp_date 
    FROM 
        ec3_ad 
    WHERE 
        hw_feat
    =AND 
        
    approved=AND 
        
    user_approved=AND 
        
    hw_region_id=103 AND 
        
    exp_date >= CURDATE()
    ORDER BY 
        hw_added DESC 
    LIMIT 20 

  4. #4
    SitePoint Wizard guelphdad's Avatar
    Join Date
    Oct 2003
    Location
    St. Catharines, ON Canada
    Posts
    1,708
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    note that curdate is merely an alias for current_date

  5. #5
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,350
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    and a non-standard one to boot

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


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
  •