Results 1 to 9 of 9

Thread: SQL date >= today? pls help

  1. #1
    Join Date
    Mar 2006
    Posts
    4

    SQL date >= today? pls help

    Hi,

    I'm making a site for my game guild. On the pages i have a section where upcoming guild events are displayed with the following query:

    SELECT * from events ORDER BY month, day LIMIT 4

    The values for month are 1-12 (Jan-Dec) and the values for day are 1-31. Year is not posted so irrelevant to this code at the moment.
    The values are posted with a html form, <select> (<option>) to be exact. I'm new to SQL/PHP and couldn't think of another way to post future dates into the sql database.

    The question is: What syntax should I add to the query so only todays and future events are diplayed on the page?
    I have tried the following but it gives a syntax error:

    SELECT * from events ORDER BY month, day WHERE month>=DATEPART(m, GETDATE()) LIMIT 4
    (haven't tried the day filter cuz I couldn't get the month filter to work)

    Any help would be appreciated.

  2. #2
    Join Date
    Sep 2002
    Posts
    5,938
    Whick rdbms do you use?

  3. #3
    Join Date
    Mar 2006
    Posts
    4
    Thank u for your reply rmiao but i don't know what "rdbms" is. If u are referring to the database language, that's MySQL 5.0..

  4. #4
    Join Date
    Sep 2005
    Posts
    168
    SELECT * from events
    WHERE month>=MONTH( NOW())
    AND day >= DAY(NOW())
    ORDER BY month, day LIMIT 4

    /** CURDATE() can be used instead of NOW() **/


    HTH
    Last edited by mikr0s; 03-05-2006 at 06:55 AM.

  5. #5
    Join Date
    Mar 2006
    Posts
    4
    Thanks very much mikr0s, that is exactly what i needed .

    When I was searching the web for solutions I already stumbled upon this option. But because i didn't get the option to define row type as MONTH or DAY, I assumed that my MySQL version didn't support these and I just didn't try it.
    Next time I have a similar problem I'll try whatever I find before bothering u all here with my newbness.
    Thanks again for the help ^^.

  6. #6
    Join Date
    Mar 2006
    Posts
    4
    Okay, new problem on the same query.
    I posted a new event that will take place next month, April 1st. It doesn't show up on the events section of the webpage. Here's the query again:

    SELECT * from events
    WHERE month >= MONTH( NOW())
    AND day >= DAY(NOW())
    ORDER BY month, day LIMIT 4

    I'm guessing it's probably because the month is different but I have no idea how to fix it. To me the query looks like it should display all events that are later than the current date..
    Any help would be appreciated again .

  7. #7
    Join Date
    Mar 2010
    Posts
    2
    SELECT * FROM events
    WHERE date(event_date)>=date( NOW())
    ORDER BY month, day LIMIT 4


    this helps you ?

  8. #8
    Join Date
    Mar 2010
    Posts
    2
    Sorry.. i didn't see the date of post below 2006.. damn..lol

    i arrived from google :S

  9. #9
    Join Date
    Sep 2002
    Posts
    5,938
    If you posted 4 years ago :-)

Posting Permissions

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