note 40183 modified in function.localtime by danbrown
| From: | danbrown@php.net | Date: | Sun, 20 Jul 2008 03:22:24 +0000 |
| Subject: | note 40183 modified in function.localtime by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-142056@lists.php.net to get a copy of this message | ||
Date select box for the current week, or whatever week you give for an offset (in seconds), returns
the string you can echo with the select box named $name:
<?php
function week_date_selectbox( $time_offset, $name )
{
if( isset( $time_offset ) )
$t = time() + $time_offset;
else
$t = time();
$wday = array("Sun ","Mon ","Tue ","Wed ","Thu
","Fri ","Sat ");
$mon = array("Jan ","Feb ","Mar ","Apr ","May
","Jun ","Jul ","Aug ","Sep ","Oct
","Nov ","Dec ");
$mybox = "<select name=\"$name\">\n";
for($ii = 0; $ii > -6; $ii--)
{
$tarr = localtime( $t + $ii * 86400, 1 );
if( $tarr["tm_wday"] == 0 )
{
// found Sunday, now make the week's strings
for($jj = 0; $jj < 7; $jj++)
{
$tarr = localtime( $t + ($jj + $ii) * 86400, 1 );
$mybox .= sprintf( " <option value=\"%04d-%02d-%02d\">%s%s%d
%d</option>\n",
((int)$tarr["tm_year"] + 1900),
$tarr["tm_mon"],
((int)$tarr["tm_mday"] + 1),
$wday[$tarr["tm_wday"]],
$mon[$tarr["tm_mon"]],
(int)$tarr["tm_mday"],
((int)$tarr["tm_year"] + 1900) );
}
break;
}
}
$mybox .= "</select>\n";
return $mybox;
}
?>
--was--
Date select box for the current week, or whatever week you give for an offset (in seconds), returns
the string you can echo with the select box named $name:
function week_date_selectbox( $time_offset, $name )
{
if( isset( $time_offset ) )
$t = time() + $time_offset;
else
$t = time();
$wday = array("Sun ","Mon ","Tue ","Wed ","Thu
","Fri ","Sat ");
$mon = array("Jan ","Feb ","Mar ","Apr ","May
","Jun ","Jul ","Aug ","Sep ","Oct
","Nov ","Dec ");
$mybox = "<select name=\"$name\">\n";
for($ii = 0; $ii > -6; $ii--)
{
$tarr = localtime( $t + $ii * 86400, 1 );
if( $tarr["tm_wday"] == 0 )
{
// found Sunday, now make the week's strings
for($jj = 0; $jj < 7; $jj++)
{
$tarr = localtime( $t + ($jj + $ii) * 86400, 1 );
$mybox .= sprintf( " <option value=\"%04d-%02d-%02d\">%s%s%d
%d</option>\n",
((int)$tarr["tm_year"] + 1900),
$tarr["tm_mon"],
((int)$tarr["tm_mday"] + 1),
$wday[$tarr["tm_wday"]],
$mon[$tarr["tm_mon"]],
(int)$tarr["tm_mday"],
((int)$tarr["tm_year"] + 1900) );
}
break;
}
}
$mybox .= "</select>\n";
return $mybox;
}
http://php.net/manual/en/function.localtime.php