elabuwa Posted November 9, 2011 Share Posted November 9, 2011 Hi guys, Have a table with a field storing values in DATETIME. Say the below records. Date 2011-11-09 08:07:32 2011-11-08 08:41:04 2011-11-01 08:51:53 2011-11-02 08:52:19 2011-11-05 08:52:56 2011-11-04 08:53:09 2011-11-08 08:53:29 2011-11-08 08:53:59 How would I write my sql statement if I need to get the records where only the date matches. Time does not need to be matched. As long as the date is matched I'm happy. I tried writing SELECT * FROM TABLE WHERE date='2011-11-08' but no success. Probably overlooking something. Your help is greatly appreciated. Cheers Elabuwa Quote Link to comment Share on other sites More sharing options...
tomfmason Posted November 9, 2011 Share Posted November 9, 2011 there are a few ways of going about this but I think using the DATE function would be the easiest. SELECT `field` FROM `table` WHERE DATE(`datefield`) = 'YYYY-MM-DD'; Quote Link to comment Share on other sites More sharing options...
fenway Posted November 9, 2011 Share Posted November 9, 2011 If you have an index on that field, then : SELECT `field` FROM `table` WHERE `datefield`>= 'YYYY-MM-DD'; Is better. Quote Link to comment Share on other sites More sharing options...
elabuwa Posted November 9, 2011 Author Share Posted November 9, 2011 thanks guys Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.