Jump to content

ranges in arrays


rbragg

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/46459-ranges-in-arrays/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/46459-ranges-in-arrays/#findComment-226114
Share on other sites

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.  ;)

Link to comment
https://forums.phpfreaks.com/topic/46459-ranges-in-arrays/#findComment-226122
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.