|
-
Apr 13th, 2004, 11:06 AM
#1
Thread Starter
Frenzied Member
last 14 dates [Resolved]
I'm trying to put the last 14 dates of the calender in a dropdown box. I thought you could just subtract a number from the date value, but I guess not. Can someone tell me how to get the last 14 dates into an array? The following doesn't work.
PHP Code:
$myarr = array(0 => (date("n/j/Y")-14), (date("n/j/Y")-13), (date("n/j/Y")-12), (date("n/j/Y")-11), (date("n/j/Y")-10), (date("n/j/Y")-9), (date("n/j/Y")-8), (date("n/j/Y")-7), (date("n/j/Y")-6), (date("n/j/Y")-5), (date("n/j/Y")-4), (date("n/j/Y")-3), (date("n/j/Y")-2), (date("n/j/Y")-1), date("n/j/Y"));
$i=0;
for($i=0;$i<15;$i++)
echo $myarr[$i] . "<br>";
Last edited by ober0330; Apr 14th, 2004 at 08:28 AM.
-
Apr 13th, 2004, 11:35 AM
#2
I use this function to produce a drop down list of days. You may need to modify it to suit your needs though. If you use a UNIX timestamp then you can add and subtract from dates as easy as you do from numbers:
PHP Code:
function maketimes($maxdays, $endofday = 0)
{
$seconds_day = 60 * 60 * 24;
$time = time(); // returns a UNIX timestamp
for ($x = 0; $x < $maxdays; $x++)
{
$array_date = getdate($time - ($x * $seconds_day));
$start_of_day = mktime (0, 0, 0, $array_date['mon'], $array_date['mday'], $array_date['year']);
if ($endofday) $start_of_day += $seconds_day - 1;
echo('<option value="' . $start_of_day . '">' .
date("l j F Y", $start_of_day) . "</option>\n");
}
}
-
Apr 13th, 2004, 12:10 PM
#3
Thread Starter
Frenzied Member
Ok... that works good... but how do I put those values into an array instead of the select box? (I will have to have an unknown number of dropdown boxes containing the dates.)
I hate arrays + php.
-
Apr 13th, 2004, 12:41 PM
#4
Frenzied Member
if $start_of_day holds the date, in the for loop, then something like this maybe:
PHP Code:
myArr = array() //put this before the loop
myArr[count(myArr)] = $start_of_day //instead of making the drop down menu.
Have I helped you? Please Rate my posts. 
-
Apr 13th, 2004, 03:54 PM
#5
Stuck in the 80s
Here's a bit shorter way to display the last 14 days (including today):
PHP Code:
<?php
for ($i = 13; $i >= 0; $i--) {
// Save in array:
$arrDates[] = date('m-d-Y', strtotime($i . ' days ago'));
echo $arrDates[count($arrDates) - 1] . '<br />';
}
?>
-
Apr 14th, 2004, 08:28 AM
#6
Thread Starter
Frenzied Member
excellent. Now... Hobo, if you could, please transfer all your knowledge to a cd or a dvd (you may need a few) and then ship that over to me, k? Thanks.
-
Apr 14th, 2004, 11:09 AM
#7
Stuck in the 80s
-
Apr 15th, 2004, 07:16 AM
#8
Thread Starter
Frenzied Member
Do you accept Visa?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|