rohit_purohit Posted February 4, 2008 Share Posted February 4, 2008 Hi Every Body I Am An Intermediate in php and mysql i am creating a stock exchange site using php and mysql now the prob is that i have to get last 5 day's entries from today from database Can AnyBody Help me...... [move]Pls It's Very Impppppppp...........[/move] Link to comment https://forums.phpfreaks.com/topic/89374-how-to-get-last-5-days-data-using-php-mysql/ Share on other sites More sharing options...
pocobueno1388 Posted February 4, 2008 Share Posted February 4, 2008 Since you didn't supply how you stored the date/time, I'm going to assume it is in yyyy/mm/dd format. So try this <?php $five_days_ago = date("Y-m-d", strtotime("- 5 DAY")); $query = mysql_query("SELECT * FROM table WHERE `date` < $five_days_ago")or die(mysql_error()); ?> Link to comment https://forums.phpfreaks.com/topic/89374-how-to-get-last-5-days-data-using-php-mysql/#findComment-457659 Share on other sites More sharing options...
obsidian Posted February 4, 2008 Share Posted February 4, 2008 If the date is stored in the database as a DATETIME or DATE type, you can easily retrieve your selected records by doing something like this with your query alone: SELECT * FROM myTable WHERE date_field >= (CURDATE() - INTERVAL 5 DAY); Link to comment https://forums.phpfreaks.com/topic/89374-how-to-get-last-5-days-data-using-php-mysql/#findComment-457679 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.