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 September 6, 2010
| Monday | 2010-09-06 |
|---|---|
| Tuesday | 2010-09-07 |
| Wednesday | 2010-09-08 |
| Thursday | 2010-09-09 |
| Friday | 2010-09-10 |
| Saturday | 2010-09-11 |
| Sunday | 2010-09-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