blmg2009 Posted September 18, 2014 Share Posted September 18, 2014 Hi there, I'm a bit of a newbie and I have done a search online, but i'm still confused. I need to search my MYSQL database in a filed named date_mod I need to search for todays date only $date=gmdate("Y-m-d"); But however the field is a datetime option so how can I search only todays date and not both date and time. Thank you for reading. Quote Link to comment https://forums.phpfreaks.com/topic/291153-searching-mysql-using-date-not-datetime/ Share on other sites More sharing options...
Barand Posted September 18, 2014 Share Posted September 18, 2014 Use the DATE() function which returns just the date portion of a datetime field eg WHERE DATE(mydatefield) = '2014-09-18' 1 Quote Link to comment https://forums.phpfreaks.com/topic/291153-searching-mysql-using-date-not-datetime/#findComment-1491534 Share on other sites More sharing options...
Solution davidannis Posted September 18, 2014 Solution Share Posted September 18, 2014 (edited) Use LIKE in your query. WHERE date_mod LIKE '$date%'; Edited September 18, 2014 by davidannis Quote Link to comment https://forums.phpfreaks.com/topic/291153-searching-mysql-using-date-not-datetime/#findComment-1491535 Share on other sites More sharing options...
blmg2009 Posted September 18, 2014 Author Share Posted September 18, 2014 Brillaint thank you, I will try this I was thinking of WHERE datetime LIKE '2014-09-18%', but I thought they should be a much better practice than this. Quote Link to comment https://forums.phpfreaks.com/topic/291153-searching-mysql-using-date-not-datetime/#findComment-1491536 Share on other sites More sharing options...
Jacques1 Posted September 18, 2014 Share Posted September 18, 2014 This LIKE hack is really not a good solution. Use the DATE() function as suggested by Barand. 1 Quote Link to comment https://forums.phpfreaks.com/topic/291153-searching-mysql-using-date-not-datetime/#findComment-1491537 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.