At 11:01 +0300 on 05/26/2004, Egor Egorov wrote about Re: DATETIME question:

John Mistler <[EMAIL PROTECTED]> wrote:
 Given a column DATETIMEcolumn (YYYY-MM-DD HH:MM:SS), is there a SELECT
 statement that will:

 select all entries whose (TIME) of DATETIMEcolumn is BETWEEN 'HH:MM:SS' AND
 'HH:MM:SS', but whose (DATE) is anything?


SELECT .. FROM t1 WHERE DATE_FORMAT(datetime_column, '%T') BETWEEN 'HH:MM:SS' AND 'HH:MM:SS';


or from version 4.1.1 you can use TIME() function for this purpose.

Description of DATE_FROMAT() and TIME function you can see at:
        http://dev.mysql.com/doc/mysql/en/Date_and_time_functions.html

Note: This is the correct solution for your current setup. One minor caveat on going this route - Since you are looking at something past the start of the field, you must read every row for the check and can not use an index over that column. Depending on the number of rows and how often you do the select (and how hard it would be to alter the code that inserts new rows), you might want to look into adding a new column that has only the time in it and make it an Index. Then you can use the index column in your select.


--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]



Reply via email to