SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict JamieJelly's Avatar
    Join Date
    Jan 2004
    Location
    London
    Posts
    226
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    selecting records matching a date in a datetime field

    Hi all,
    I have a record with a datetime field in (it is for appointment dates and times).

    I however want to be able to query the table to find all appointments for that particular day, but the database doesnt seem to return any results unless I specify the time as well.

    For example, a record has the appointment set to '2004-06-25 20:30:00'
    and if I query SELECT * FROM leads WHERE appointment='2004-06-25' nothing is returned.

    Can anyone help me?
    International calls from the UK
    Cheap International Calls

  2. #2
    SitePoint Guru
    Join Date
    Jan 2004
    Location
    Uppsala, sverige
    Posts
    697
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    Code:
    SELECT * 
    FROM leads 
    WHERE appointment between '2004-06-25 00:00:00' and '2004-06-25 23:59:59'

  3. #3
    SitePoint Zealot kamm's Avatar
    Join Date
    Nov 2003
    Location
    Espaņa
    Posts
    162
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You may find this useful as well...

    Code:
    SELECT * 
    FROM `leads` 
    WHERE appointment BETWEEN SUBDATE(NOW(),INTERVAL 1 DAY) AND NOW()
    http://dev.mysql.com/doc/mysql/en/Da...functions.html

    hasta later,
    kamm...

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,251
    Mentioned
    59 Post(s)
    Tagged
    3 Thread(s)
    kamm, how is that useful? those are appointments
    within the last 24 hours -- some from yesterday, some from today

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

  5. #5
    SitePoint Zealot kamm's Avatar
    Join Date
    Nov 2003
    Location
    Espaņa
    Posts
    162
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah you're right (again) - it's not gonna help in this situation...

    Oh oh --> off to the back of class again... (they don't have smilies with dunces hats)

    hasta later,
    kamm...

  6. #6
    SitePoint Addict JamieJelly's Avatar
    Join Date
    Jan 2004
    Location
    London
    Posts
    226
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks very much guys, the "between" method came to me in my sleep. Honest it did....
    International calls from the UK
    Cheap International Calls


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
  •