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
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?

Link to comment
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.