Skip navigation.
Home
That which cannot be rendered in binary is by definition a delusion
 

Date Ranges

 Write a PHP code which, for a given date, generates an array which contains the 7 days (format yyyy-mm-dd) of the considered week ordered from Sunday to Saturday. The given date will have a 'day' as key.

 

Days around date:

 

Week starting February 6, 2012

Monday 2012-02-06
Tuesday 2012-02-07
Wednesday 2012-02-08
Thursday 2012-02-09
Friday 2012-02-10
Saturday 2012-02-11
Sunday 2012-02-12

 

Source

<?php
$search_date = (array_key_exists('search_date', $_REQUEST)) ? $_REQUEST['search_date'] : date('Y/m/d');
$monday = new DateTime($search_date);
echo '<pre>', print_r($back_a_day, 1), '</pre>';
while (intval($monday->format('N')) > 1){
$monday->modify('-1 day');
}

?>
<p>Enter a date to find the weekly dates around it</p>
<form method="POST">
    <table>
        <tbody>
            <tr>
                <th>Days around date:</th>
                <td><input type="text" value="<?php print $search_date  ?>" name="search_date" /></td>
            </tr>
        </tbody>
    </table>
</form>
<p>&nbsp;</p>
<h3>Week starting <?= $monday->format('F j, Y') ?></h3>
<table>
    <tbody>
        <? do { ?>
        <tr>
            <th><?= $monday->format('l') ?></th>
            <td><?= $monday->format('Y-m-d') ?></td>
        </tr>
        <? 
$monday->modify('+1 day');
} while (intval($monday->format('N')) > 1) ?>
    </tbody>
</table>
AttachmentSize
nor1_date_range.php.txt939 bytes

Post new comment

  • Allowed HTML tags: <a> <p> <span><small> <div> <h1> <h2> <h3> <h4> <h5> <h6> <img> <map> <area> <hr> <br> <br /> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <em> <b> <u> <i> <strong> <font> <del> <ins> <sub> <sup> <quote> <blockquote> <pre> <address> <code> <cite> <embed> <object> <param> <strike> <caption>
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options