Select news between to dates

  • Hi,

    I have the following problem. I have a table with news-items with a start- and end-date.

    Now I only wnat to show items that are between these to dates.

    How do I have to do that.

    I thought it had to be something like this.

    Select * from tbl_nieuws where date(now) between start_date and end_date

    This however doesn't work.

    I hope someone can help me.

    Kind regards,

    Martin Smits

  • Try GETDATE()

    insted of date(now)

    If that doesn't work, post the error you are getting.

  • info (6/2/2009)


    I have a table with news-items with a start- and end-date.

    Hi,

    Can you show the table schema with data?

    ARUN SAS

  • Here you are

    id bigint(11) Nee auto_increment

    titel text utf8_unicode_ci Ja NULL

    introductie longtext utf8_unicode_ci Ja NULL

    bericht longtext utf8_unicode_ci Ja NULL

    kader varchar(255) utf8_unicode_ci Ja NULL

    start_datum date Ja NULL

    eind_datum date Ja NULL

    bericht_tonen tinyint(1) Nee 0

  • Hi,

    Ok, suppose you need to show the records having the date range of current date,

    Then you try Tom Brown coding to get the result.

    Select * from yourtable where getdate() between start_datum and eind_datum

    ARUN SAS

  • Hi,

    this is what i've tried:

    Select * from `tbl_nieuws` where getdate() between `start_datum` and `eind_datum`

    This provides the following error.

    #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '() between `start_datum` and `eind_datum`

    LIMIT 0, 30' at line 1

    Kind regards.

  • Hi,

    Use the CURRENT_TIMESTAMP instead of the getdate()

    ARUN SAS

  • It works!!! Thanks a lot.

    Kind regards,

    Martin Smits

  • Please note that this is primarily a SQL Server site, so if you have a MySQL question, let us know that beforehand so that we don't give you the wrong answer.

    [font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
    Proactive Performance Solutions, Inc.
    [/font]
    [font="Verdana"] "Performance is our middle name."[/font]

Viewing 9 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic. Login to reply