groovejuice Posted June 17, 2011 Share Posted June 17, 2011 I am just beginning with php/mysql and am looking for help coding this. I need to filter and display certain values from a table if a datediff is more than 182 days. select last name, first name, email from table WHERE DATEDIFF ( DATE1 (date from drop down selection) - DATE2 (date from proj_date column) > 182) Thanks Quote Link to comment https://forums.phpfreaks.com/topic/239680-select-from-mysql-using-datediff/ Share on other sites More sharing options...
xyph Posted June 17, 2011 Share Posted June 17, 2011 Do you really have spaces in your column names? You want SELECT `lastname`, `firstname`, `email` FROM `table` WHERE DATEDIFF( 'YYYY-MM-DD', `proj_date`) > 182 Where YYYY-MM-DD are the values from your dropdown. Quote Link to comment https://forums.phpfreaks.com/topic/239680-select-from-mysql-using-datediff/#findComment-1231227 Share on other sites More sharing options...
groovejuice Posted June 18, 2011 Author Share Posted June 18, 2011 @xyph thank you very much for your reply! I will test this code tomorrow. I do not have spaces in the column names, I just tried to illustrate the logic and did not worry about syntax since I'm working from a manual for each bit of code. I appreciate your assistance very much. Quote Link to comment https://forums.phpfreaks.com/topic/239680-select-from-mysql-using-datediff/#findComment-1231296 Share on other sites More sharing options...
Skylight_lady Posted June 18, 2011 Share Posted June 18, 2011 Please note that if DATE1 is the current or past date and DATE2 is a date in the future. Then your date will be minus the number of days. eg: SELECT DATEDIFF('2010-11-30 23:59:59','2010-12-31'); = -31 Quote Link to comment https://forums.phpfreaks.com/topic/239680-select-from-mysql-using-datediff/#findComment-1231303 Share on other sites More sharing options...
xyph Posted June 18, 2011 Share Posted June 18, 2011 That shouldn't affect output, as he wants to see if DATE1 is 182 days AFTER DATE2. Quote Link to comment https://forums.phpfreaks.com/topic/239680-select-from-mysql-using-datediff/#findComment-1231337 Share on other sites More sharing options...
Skylight_lady Posted June 18, 2011 Share Posted June 18, 2011 Xyph, a simple question......how do you know that? Did he say that was the case? No. Quote Link to comment https://forums.phpfreaks.com/topic/239680-select-from-mysql-using-datediff/#findComment-1231395 Share on other sites More sharing options...
xyph Posted June 18, 2011 Share Posted June 18, 2011 When he writes an example like this DATE1 (date from drop down selection) - DATE2 (date from proj_date column) > 182 It seems like he won't care about negative vales, he only cares if the user input is more than 182 days after, not before. Quote Link to comment https://forums.phpfreaks.com/topic/239680-select-from-mysql-using-datediff/#findComment-1231518 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.