rbragg Posted April 10, 2007 Share Posted April 10, 2007 I have some dates stored in my db. Here an example of the orientation: 2007-04-10 I am trying to display results from the db that fall into a range. I have built my date like so: <?php $startDate = "$searchYearS-$searchMonthS-$searchDayS"; $endDate = "$searchYearE-$searchMonthE-$searchDayE"; $dateRange = range('$startDate', '$endDate'); ?> I know that this builds an array. I would like to know how I can use this to set a variable to use in a SQL statement. Thanks in advance! Quote Link to comment Share on other sites More sharing options...
boo_lolly Posted April 10, 2007 Share Posted April 10, 2007 you can do this in your sql query. something like: $sql = "SELECT * FROM your_table WHERE date = ". range($startDate, $endDate) .""; but you're going to need strtotime(). i don't think range() will recognize a string as an argument for a date. Quote Link to comment Share on other sites More sharing options...
rbragg Posted April 10, 2007 Author Share Posted April 10, 2007 In my db, I have stored service_date as tinytext and not a date. Is it safe to say that strtotime will not work for me? Also, as text, would "2007-04-03" to "2007-04-05" ("2007-04-03", "2007-04-04", "2007-04-05") not be seen as a range? Quote Link to comment Share on other sites More sharing options...
boo_lolly Posted April 10, 2007 Share Posted April 10, 2007 In my db, I have stored service_date as tinytext and not a date. Is it safe to say that strtotime will not work for me? Also, as text, would "2007-04-03" to "2007-04-05" ("2007-04-03", "2007-04-04", "2007-04-05") not be seen as a range? well there's only one way to find out, but i'm pretty sure it won't work like that. if you have a column in your database table that is going to be used for dates... then make it a date column, not a tinytext column. it will save you a LOT of headache in the future. Quote Link to comment Share on other sites More sharing options...
rbragg Posted April 10, 2007 Author Share Posted April 10, 2007 I had tried (in short): <?php $dateRange = range('$startDate', '$endDate'); $querySearch.= " AND configlog_action.service_date = '$dateRange' "; ?> This did not work for me. I was just making sure it wasn't possible and that I didn't overlook something. Thanks for the tip about the date column. I will try that out. I may have more questions for you later. Quote Link to comment Share on other sites More sharing options...
Barand Posted April 10, 2007 Share Posted April 10, 2007 SELECT * FROM mytable WHERE date BETWEEN '$startdate' AND '$enddate'. Make sure start and end are in YYYY-mm-dd format. Quote Link to comment 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.