Results 1 to 8 of 8

Thread: last 14 dates [Resolved]

  1. #1

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945

    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(=> (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.
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  2. #2
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906
    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 (000$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");
        }


    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  3. #3

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945
    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.
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  4. #4
    Frenzied Member Acidic's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    1,090
    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.

  5. #5
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    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 />';
        }

    ?>
    My evil laugh has a squeak in it.

    kristopherwilson.com

  6. #6

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945
    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.
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  7. #7
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by ober5861
    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.
    Sure, for the remarkable low price of $399.99, I can make that happen. And I can make it all fit on a 1.5MB floppy, as well.

    What a deal, huh?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  8. #8

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945
    Do you accept Visa?
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width