phpmikey Posted April 4, 2010 Share Posted April 4, 2010 hi, i am using the following code to retrieve information for todays date: <?php $query = "select * from customer where DATE (date) = DATE(NOW())"; $result = @mysql_query($query, $connection) or die ("Unable to perform query.<br />$query<br/>"); $num_rows = mysql_num_rows($result); echo "$num_rows"; ?> i cant seem to find any code to extract information from yesterdays date. can you help please? Quote Link to comment https://forums.phpfreaks.com/topic/197509-retrieving-mysql-information-using-yesterdays-date/ Share on other sites More sharing options...
premiso Posted April 4, 2010 Share Posted April 4, 2010 The @ is supressing any useful errors. Try this and see what the error says, (my bet is the DATE being used a column name). $result = mysql_query($query, $connection) or trigger_error("MySQL Query Failed: " . mysql_error()); See what the shows ya. Quote Link to comment https://forums.phpfreaks.com/topic/197509-retrieving-mysql-information-using-yesterdays-date/#findComment-1036609 Share on other sites More sharing options...
litebearer Posted April 4, 2010 Share Posted April 4, 2010 perhaps this snippet may point you the way... WHERE date = DATE_ADD(CURDATE(), INTERVAL -1 DAY) Quote Link to comment https://forums.phpfreaks.com/topic/197509-retrieving-mysql-information-using-yesterdays-date/#findComment-1036614 Share on other sites More sharing options...
phpmikey Posted April 4, 2010 Author Share Posted April 4, 2010 no the code i posted is fully working code and retrieves the information i need data entered for todays date. the question was how can i adapt this to retrieve information for yesterdays date. for example show all records where date = yesterdays date. Quote Link to comment https://forums.phpfreaks.com/topic/197509-retrieving-mysql-information-using-yesterdays-date/#findComment-1036615 Share on other sites More sharing options...
phpmikey Posted April 4, 2010 Author Share Posted April 4, 2010 perhaps this snippet may point you the way... WHERE date = DATE_ADD(CURDATE(), INTERVAL -1 DAY) thanks il try that now Quote Link to comment https://forums.phpfreaks.com/topic/197509-retrieving-mysql-information-using-yesterdays-date/#findComment-1036616 Share on other sites More sharing options...
phpmikey Posted April 4, 2010 Author Share Posted April 4, 2010 perhaps this snippet may point you the way... WHERE date = DATE_ADD(CURDATE(), INTERVAL -1 DAY) EDIT! that did work when i inserted my saved date value. $query = "select * from customer WHERE date (date) = DATE_ADD(CURDATE(), INTERVAL -1 DAY)"; thanks very much for your help Quote Link to comment https://forums.phpfreaks.com/topic/197509-retrieving-mysql-information-using-yesterdays-date/#findComment-1036618 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.