SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict
    Join Date
    Jan 2004
    Location
    New York
    Posts
    254
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    [solved]using DATE_FORMAT in the WHERE Clause

    I did a search and all they showed was DATE_FORMAT being used in the SELECT part of the query. But I want to use DATE_FORMAT so it generalises the date column into the month.

    Here is my query:

    Code:
    SELECT * FROM news WHERE DATE_FORMAT(news.thedate,'%Y-%d') = '2005-09';
    Obviously, this is not working. The query goes through but no rows are returned. What can I do?

    Never mind I got it. Parameters in mySQL are confusing. its '%Y-%m'
    Last edited by Atealtha; Nov 28, 2004 at 15:41. Reason: figured it out myself

  2. #2
    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)
    you might try %m (month) instead of %d (day)

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


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
  •