Searching against a DATETIME col

    Date: 06/25/08 (MySQL Communtiy)    Keywords: mysql, sql

    "mydate" is a DATETIME field. I need to search this field with DATE input and ran into this:

    mysql> SELECT COUNT(*) FROM program WHERE mydate LIKE '2008-04-22%';
    +-------------------+
    | COUNT(*) |
    +-------------------+
    | 538 |
    +-------------------+
    1 row in set (0.08 sec)

    mysql> SELECT COUNT(*) FROM program WHERE DATE(mydate) = '2008-04-22';
    +-------------------+
    | COUNT(*) |
    +-------------------+
    | 0 |
    +-------------------+
    1 row in set (0.06 sec)


    My table may not be normalized properly (DATETIME instead of separate DATE and TIME fields), but I'd like to know the best approach for searching based on the current DATETIME field.

    Source: http://community.livejournal.com/mysql/129354.html

« Selective Replication in... || Memory leak? »


antivirus | apache | asp | blogging | browser | bugtracking | cms | crm | css | database | ebay | ecommerce | google | hosting | html | java | jsp | linux | microsoft | mysql | offshore | offshoring | oscommerce | php | postgresql | programming | rss | security | seo | shopping | software | spam | spyware | sql | technology | templates | tracker | virus | web | xml | yahoo | home