Jump to content

Array of Dates within a given week


tekrscom

Recommended Posts

Hi, I was wondering if someone could help me with this aggravating little problem I'm having... I feel like I am getting close, but as of yet, no cigar...

 

So what I am trying to do is list all of the dates of the week, within a specified week... Here's what I got so far...

The $_SESSION['SessionWeekEndingDate'] is in the standard yyyy-mm-dd format...

            <select name="DayOfWeek">
                <?
                for ($i = 1; $i < 8 ;$i++)
                {
                        $myarray[] = date("l, M j, Y", strtotime("$_SESSION[sessionWeekEndingDate]"));
                }
                foreach($myarray as $var)
                    {
                    echo '<option value="', $var, '">', $var, '</option>';
                    }
                ?>
            </select>

Link to comment
https://forums.phpfreaks.com/topic/205324-array-of-dates-within-a-given-week/
Share on other sites

Thank you, that definately puts me on a better track than I was... the only problem now is that, that gives the dates after the $_SESSION['SessionWeekEndingDate'], instead of the dates prior to that date...

 

                for ($i = 0; $i < 7 ;$i++)
                {
                        $myarray[] = date("l, M j, Y", strtotime("$_SESSION[sessionWeekEndingDate]") + 24 * 3600 * $i);
                }

                for ($i = 0; $i < 7 ;$i++)
                {
                        $myarray[] = date("l, M j, Y", strtotime("$_SESSION[sessionWeekEndingDate]") - 24 * 3600 * (7 - $i));
                }
[/cod

Thank you... That worked very well,... Here's the final code...

 

            <select name="DayOfWeek">
                <?
                for ($i = 0; $i < 7 ;$i++)  {
                     $myarray[] = date("l, M j, Y", strtotime("$_SESSION[sessionWeekEndingDate]") - 24 * 3600 * (6 - $i));
                    }
                foreach($myarray as $var)
                    {
                    echo '<option value="', $var, '">', $var, '</option>';
                    }
                ?>
            </select>

 

                for ($i = 0; $i < 7 ;$i++)
                {
                        $myarray[] = date("l, M j, Y", strtotime("$_SESSION[sessionWeekEndingDate]") - 24 * 3600 * (7 - $i));
                }
[/cod

Why use an array? Just use the data when you generate it:

            <select name="DayOfWeek">
                <?php
                for ($i = 0; $i < 7 ;$i++)  {
                     $var = date("l, M j, Y", strtotime("$_SESSION[sessionWeekEndingDate]") - 24 * 3600 * (6 - $i));
                     echo '<option value="', $var, '">', $var, '</option>';
                }
                ?>
            </select>

 

Ken

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.