SQL Filter on Date and Time Field

Discussion in 'MySQL' started by wizzard, Sep 14, 2008.

  1. #1
    Hello,

    I have table with articles that has the fields (id, title, text, image, date, time).

    The date field is a date field and the time field is a time field.

    But i want to filter on my site that it must only show articles that be not later than the current time. So if i have added an article to show today but on a later hour than the current one it must not be visible.

    I'm stuck with this i know how to filter on the current date. I'm doing it this way date <= '".date ("Y-m-d")."'.

    But can some helps me how i can filter on date and time ?

    Cheers,
    Kris
     
    wizzard, Sep 14, 2008 IP
  2. mwasif

    mwasif Active Member

    Messages:
    816
    Likes Received:
    23
    Best Answers:
    1
    Trophy Points:
    70
    #2
    It is better to provide your current query, 2 sample records and the required output.
     
    mwasif, Sep 14, 2008 IP
  3. chisara

    chisara Peon

    Messages:
    141
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #3
    select title, text, image from articles where date<=curdate() and time<=curtime();
    That should do the trick assuming you are using Mysql.
    I suspect that the <=". date(Y-m-d")."'. is an PHP thingy to get the currect date for this to work perfectly the www and DB server clocks should be running roughly the same date and time.
     
    chisara, Sep 15, 2008 IP