bowlingtourneycom Posted January 30, 2007 Share Posted January 30, 2007 Having issues coming up with the proper code/select statement.My DB has three fields in particular. start_date_month, start_date_day, start_date_year.I am trying to get results that are set to happen within a 2 week time period from today's date.How would I go about coding this?I did a $current_date = mktime(0,0,0, date('n'), date('d'), date('Y'));, but I am confused on how to get the right info from the DB.Any help would be great! Quote Link to comment https://forums.phpfreaks.com/topic/36263-phpmysql-select-statement-processing/ Share on other sites More sharing options...
utexas_pjm Posted January 30, 2007 Share Posted January 30, 2007 You can do this:[code]SELECT * FROM `your_table` WHERE `some_date` BETWEEN NOW() AND (DATE_ADD(NOW(), INTERVAL 14 DAY))[/code]Best,Patrick Quote Link to comment https://forums.phpfreaks.com/topic/36263-phpmysql-select-statement-processing/#findComment-172512 Share on other sites More sharing options...
anatak Posted January 30, 2007 Share Posted January 30, 2007 I am I correct in thinking that you use 3 fields to store the date in your database ?one field for year one for month and one for days ?say you want to select the dates from january 2 2007 till 16 is easyselect * from table where year is 2007 and month is 01 and day is =< 02 and day is => 16but you will run into trouble soon because not all the months have the same number of days.I would suggest working with a date field in your database instead of the 3 separate fields.that way you can use all the mysql date functions. (google for mysql date functions if you want to have an idea what is possible) Quote Link to comment https://forums.phpfreaks.com/topic/36263-phpmysql-select-statement-processing/#findComment-172562 Share on other sites More sharing options...
bibby Posted January 30, 2007 Share Posted January 30, 2007 [url=http://dev.mysql.com/doc/refman/4.1/en/date-and-time-functions.html]http://dev.mysql.com/doc/refman/4.1/en/date-and-time-functions.html[/url] Quote Link to comment https://forums.phpfreaks.com/topic/36263-phpmysql-select-statement-processing/#findComment-172567 Share on other sites More sharing options...
utexas_pjm Posted January 30, 2007 Share Posted January 30, 2007 [quote]My DB has three fields in particular. start_date_month, start_date_day, start_date_year.[/quote]Didn't catch that. I would suggest consolidating these values in a date or datetime field. Will make your life much easier when doing any sort of date arithmetic.Patrick Quote Link to comment https://forums.phpfreaks.com/topic/36263-phpmysql-select-statement-processing/#findComment-172706 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.