phppaper Posted November 18, 2010 Share Posted November 18, 2010 Hello, In my Mysql database, it has a datetime field. and I have created a $today = date('Y-m-d H:i:s'); <- today's date and time How do I write a query to run in PHP in order to get all today's items by comparing datetime field and $today? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/219051-get-all-of-the-todays-items-from-mysql/ Share on other sites More sharing options...
revraz Posted November 18, 2010 Share Posted November 18, 2010 You don't need variable for $today, just use now(). select * from mytable where mydatefield = now(); Quote Link to comment https://forums.phpfreaks.com/topic/219051-get-all-of-the-todays-items-from-mysql/#findComment-1135969 Share on other sites More sharing options...
PFMaBiSmAd Posted November 18, 2010 Share Posted November 18, 2010 Time is fairly specific and changes all the time. Every new second that goes by makes it kind of hard to match other time values. select * from your_table where DATE(your_datetime_field) = CURDATE(); Quote Link to comment https://forums.phpfreaks.com/topic/219051-get-all-of-the-todays-items-from-mysql/#findComment-1136038 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.