mySQL - Select ONLY TODAY Problem? Only shows >Today?!

Discussion in 'MySQL' started by fdoze, Nov 12, 2008.

  1. #1
    Hi,

    I have this table for events :

    2 Rows:
    start_date field - datetime:
    1.---> 2008-11-22 16:17:10
    2.---> 2008-11-20 12:14:16

    Using this:
    SELECT title, DAY(start_date) AS `myD` , MONTH(start_date) AS `MyM` , YEAR(start_date) AS `myY`
    FROM `events`
    WHERE 'myD' = '20'
    PHP:
    Does not return any!!



    But
    SELECT title, DAY(start_date) AS `myD` , MONTH(start_date) AS `MyM` , YEAR(start_date) AS `myY`
    FROM `events`
    WHERE 'myD' > '20'
    PHP:
    Return the two rows.




    Using
    SELECT title, DAY(start_date) AS `myD` , MONTH(start_date) AS `MyM` , YEAR(start_date) AS `myY`
    FROM `events`
    WHERE 'myD' >= '20' AND 'myD' < '21'
    PHP:
    Return nothing too!




    How can I get just the rows that are from TODAY!??
    I assume 20 - to be today day... Its mssing month , year.. etc..

    Could you please help me on this?

    Thanks.
     
    fdoze, Nov 12, 2008 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    Try:

    SELECT title, DAY(start_date) AS myD, MONTH(start_date) AS MyM, YEAR(start_date) AS myY
    FROM events
    WHERE DAY(start_date) = 20 AND MONTH(start_date) = 11 AND YEAR(start_date) = 2008
     
    jestep, Nov 12, 2008 IP
  3. fdoze

    fdoze Peon

    Messages:
    205
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    That works but... Why only the month dont work? is because I was usin the alias?
     
    fdoze, Nov 13, 2008 IP
  4. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #4
    No, it was because you were using a single quote 'myD'. myD should work but 'myD' will not work.
     
    jestep, Nov 13, 2008 IP
  5. Doron

    Doron Banned

    Messages:
    26
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    This is a very resource consuming query, I saw this once on 200k rows table running for 30 seconds.

    Try:
    SELECT title, DAY(start_date) AS myD, MONTH(start_date) AS MyM, YEAR(start_date) AS myY
    FROM events
    Where Date(start_date) = CURDATE()
     
    Doron, Nov 13, 2008 IP