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. 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' Link to comment https://forums.phpfreaks.com/topic/291153-searching-mysql-using-date-not-datetime/#findComment-1491534 Share on other sites More sharing options...
davidannis Posted September 18, 2014 Share Posted September 18, 2014 Use LIKE in your query. WHERE date_mod LIKE '$date%'; 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. 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. 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
Archived
This topic is now archived and is closed to further replies.