jeff5656 Posted July 18, 2012 Share Posted July 18, 2012 I am trying to select records with today's date but am getting zero hits: $currdate= date("y-m-d"); $query = "select id from table1 where some_date = '$currdate' the problem is that the date is stored as a datetime so there is a time after it. How do I modify the above query to select for today's date and ignore the time part? Quote Link to comment https://forums.phpfreaks.com/topic/265869-selecting-date-correctly/ Share on other sites More sharing options...
scootstah Posted July 18, 2012 Share Posted July 18, 2012 You use MySQL's functions. $query = "select id from table1 where some_date = NOW()" Quote Link to comment https://forums.phpfreaks.com/topic/265869-selecting-date-correctly/#findComment-1362330 Share on other sites More sharing options...
PFMaBiSmAd Posted July 18, 2012 Share Posted July 18, 2012 To reference just the date part of your datetime value - http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_date Quote Link to comment https://forums.phpfreaks.com/topic/265869-selecting-date-correctly/#findComment-1362335 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.