SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot
    Join Date
    Nov 2005
    Posts
    171
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    SQL query using date not working correctly

    Hi all,
    Ive got an sql query with the following as the where clause;

    WHERE d.date >=2006-01-18

    Therefore, i assume that for a row in the table to be true to this where clause it must have a date that is after 18/01/2006 (dd/mm/yyyy) i.e. any time after the 18th of Jan, 2006.

    This is what is confusing me, in my table I have the following date valuse:

    2005-09-30
    2005-11-16
    2005-12-12
    2005-12-21
    2006-01-04
    2006-01-06
    2006-01-12

    Therefore, I would guess that the following date valuse should appear in the results of the SQl query: 0 rows

    However, when I execute this quesry for real, all of the following values will appear in the results:

    2005-11-16
    2005-12-12
    2005-12-21
    2006-01-06
    2006-01-12

    Any ideas why?

  2. #2
    SitePoint Addict
    Join Date
    Feb 2004
    Location
    Staffordshire, UK & Florida, USA
    Posts
    314
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You should enclose the date in single quotes:

    ...WHERE d.date >= '2006-01-18'


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
  •