Re: best way to do this with arrays...
| From: | Torsten Roehr | Date: | Mon, 24 May 2004 14:14:21 +0000 |
| Subject: | Re: best way to do this with arrays... | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-186826@lists.php.net to get a copy of this message | ||
"Edward Peloke" <epeloke@echoman.com> wrote in message
news:NKEFLLFBJFIKEGAGKPCACEJJDCAA.epeloke@echoman.com...
> Hello,
>
> I have a table in a database that holds begin and end dates...I would like
> to select all the begin and end dates for a certain id, then add those
> dates, plus the dates between them to an array...example.
>
> Begin date 2004-07-04
> End date 2004-07-09
>
> I want the array to hold,
> 2004-07-04,2004-07-05,2004-07-06,2004-07-07,2004-07-08,2004-07-09
>
> I would then loop to the next row in the db and continue to add to the
> array. I can't simply add one to the last two characters. What's the
best
> way? I ask becuase I am using a nice php calender script and I want to
> change the background color of the day's cell if it falls between the
begin
> and end dates of the calender. I thought I could just add the dates to an
> array, then use the in array function on each date.
As you only want to check if a certain date falls within the specified time
period, this could be done easier by converting the dates to timestamps:
$start = '2004-07-04';
$end = '2004-07-09';
$check = '2004-07-06'; // the date you want to check
$timestampStart =
mktime(0,0,0,substr($start,5,2),substr($start,8,2),substr($start,0,4));
$timestampEnd =
mktime(0,0,0,substr($end,5,2),substr($end,8,2),substr($end,0,4));
$timestampCheck =
mktime(0,0,0,substr($check,5,2),substr($check,8,2),substr($check,0,4));
if ($timestampCheck >= $timestampStart && $timestampCheck <= $timestampEnd)
{
// do what you want
}
Haven't tested it. Hope it works for you.
Regards,
Torsten Roehr