Date Ranges
Submitted by bingomanatee on 7 March, 2010 - 10:47
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.
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> </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>
| Attachment | Size |
|---|---|
| nor1_date_range.php.txt | 939 bytes |

Post new comment