jtelo Posted July 11, 2010 Share Posted July 11, 2010 I have a table with the columns code, user and date (in the timestamp format. Example: 2010-07-09 11:23:42). I'm trying to make a query with PHP and mySQL to return the rows with the timestamp of the previous day, but can't make it work. Can someone please help me? Quote Link to comment https://forums.phpfreaks.com/topic/207394-select-previous-day-timestamp/ Share on other sites More sharing options...
Topshed Posted July 11, 2010 Share Posted July 11, 2010 I am no expert but as the time stamp in a number of units sine inception I would have thought using now() and minus the figure for 24 hours would do the job ?? Just a thought Topshed Quote Link to comment https://forums.phpfreaks.com/topic/207394-select-previous-day-timestamp/#findComment-1084369 Share on other sites More sharing options...
jtelo Posted July 11, 2010 Author Share Posted July 11, 2010 I am no expert but as the time stamp in a number of units sine inception I would have thought using now() and minus the figure for 24 hours would do the job ?? Just a thought Topshed With this i get all the rows of the previous days, but can't make it return only one day: SELECT * FROM table WHERE date<NOW() Quote Link to comment https://forums.phpfreaks.com/topic/207394-select-previous-day-timestamp/#findComment-1084409 Share on other sites More sharing options...
PFMaBiSmAd Posted July 11, 2010 Share Posted July 11, 2010 SELECT * FROM table WHERE DATE(date) = CURDATE() - INTERVAL 1 day Quote Link to comment https://forums.phpfreaks.com/topic/207394-select-previous-day-timestamp/#findComment-1084433 Share on other sites More sharing options...
jtelo Posted July 12, 2010 Author Share Posted July 12, 2010 SELECT * FROM table WHERE DATE(date) = CURDATE() - INTERVAL 1 day Thank you all for the help. I got what i wanted with this: select * from table where `date` BETWEEN DATE_SUB(CURDATE(), INTERVAL 1 DAY) AND CURDATE() Quote Link to comment https://forums.phpfreaks.com/topic/207394-select-previous-day-timestamp/#findComment-1084935 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.