jakebur01 Posted October 18, 2007 Share Posted October 18, 2007 How do I query a date range? I have a date column in my mysql table. I want to select a range of rows between : Ex. 2007-08-05 through 2007-08-30 . I also would like to have the page that sends the query as a form.. option value that shows all of the available dates, so i can select a from date and a to date. I have never done anything with dates before, I need some help getting going. Quote Link to comment https://forums.phpfreaks.com/topic/73810-solved-selecting-date-range/ Share on other sites More sharing options...
kernelgpf Posted October 18, 2007 Share Posted October 18, 2007 $query=mysql_query("select column1,column2 from table1 where date1 <= '$beginningdate' and date1 >= '$enddate'"); That should set you on the right track. =] Quote Link to comment https://forums.phpfreaks.com/topic/73810-solved-selecting-date-range/#findComment-372352 Share on other sites More sharing options...
jakebur01 Posted October 18, 2007 Author Share Posted October 18, 2007 Thanks! What about my selection page where I select my dates. How could I loop through and create option values without displaying the same date twice? Quote Link to comment https://forums.phpfreaks.com/topic/73810-solved-selecting-date-range/#findComment-372355 Share on other sites More sharing options...
jakebur01 Posted October 18, 2007 Author Share Posted October 18, 2007 how do I select values from mysql but only display a certain value once. Ex. If I have a column that has 8 "3's", but I only want the 3 displayed one time so that it is not repeated. Quote Link to comment https://forums.phpfreaks.com/topic/73810-solved-selecting-date-range/#findComment-372457 Share on other sites More sharing options...
jakebur01 Posted October 18, 2007 Author Share Posted October 18, 2007 bump. Quote Link to comment https://forums.phpfreaks.com/topic/73810-solved-selecting-date-range/#findComment-372662 Share on other sites More sharing options...
Daukan Posted October 18, 2007 Share Posted October 18, 2007 "SELECT DISTINCT date1 FROM table1 WHERE date1 <= '$beginningdate' AND date1 >= '$enddate' GROUP BY date1" Might work if I have the syntax right. Quote Link to comment https://forums.phpfreaks.com/topic/73810-solved-selecting-date-range/#findComment-372670 Share on other sites More sharing options...
jakebur01 Posted October 18, 2007 Author Share Posted October 18, 2007 That's not what i'm trying to do. I want to select all of the available dates from a column, but not the same one twice. ex.: [b]date1 column[/b] 2007-08-05 2007-08-05 2007-08-05 2007-08-05 2007-08-06 2007-08-06 2007-08-08 2007-08-08 2007-08-11 2007-08-12 and select only the available dates and not the same one twice. like: 2007-08-05 2007-08-06 2007-08-08 2007-08-11 2007-08-12 Quote Link to comment https://forums.phpfreaks.com/topic/73810-solved-selecting-date-range/#findComment-372686 Share on other sites More sharing options...
Daukan Posted October 18, 2007 Share Posted October 18, 2007 Thats what DISTINCT does.... It will select only one of each date instead of multiples Quote Link to comment https://forums.phpfreaks.com/topic/73810-solved-selecting-date-range/#findComment-372691 Share on other sites More sharing options...
jakebur01 Posted October 18, 2007 Author Share Posted October 18, 2007 ok thanks. Quote Link to comment https://forums.phpfreaks.com/topic/73810-solved-selecting-date-range/#findComment-372698 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.