I made a simple program that originally meant output from Sunday to Saturday, but now I'm making a change in day and week, and the result I want is this:
2014-9-28 (Sunday)
2014-9-29 (Monday)
2014-9-30 (Tuesday)
2014-10-1 (Wednesday)
2014-10-2 (Thursday)
2014-10-3 (Fri)
2014-10-4 (Saturday)
by 2014-10-5 (Sunday) ..... One analogy, only the date is changing, and the week does not change, how does this come true? This is my original program,
function Getweek ($day) { $days = array (' Sunday ', ' Monday ', ' Tuesday ', ' Wednesday ', ' Thursday ', ' Friday ', ' Saturday '); $day = Explode ('-', $day); return $days [Date (' W ', Mktime (0,0,0, $day [1], $day [2], $day [0])];}
Reply to discussion (solution)
What does that mean?
function Getweek ($day) { $days = array (' Sunday ', ' Monday ', ' Tuesday ', ' Wednesday ', ' Thursday ', ' Friday ', ' Saturday '); return $days [Date (' W ', Strtotime ($day))];} $date = ' 2014-09-29 '; if ($w = Date (' W ', Strtotime ($date))) $date = Date (' y-m-d ', Strtotime ("-$w Day $date")), and for ($i = 0; $i < 7, $i + +) {$day = date (' y-m-d ', Strtotime ("$i Day $date"); Echo $day. " (". Getweek ($day).") \ n ";}
What does that mean?
function Getweek ($day) { $days = array (' Sunday ', ' Monday ', ' Tuesday ', ' Wednesday ', ' Thursday ', ' Friday ', ' Saturday '); return $days [Date (' W ', Strtotime ($day))];} $date = ' 2014-09-29 '; if ($w = Date (' W ', Strtotime ($date))) $date = Date (' y-m-d ', Strtotime ("-$w Day $date")), and for ($i = 0; $i < 7, $i + +) {$day = date (' y-m-d ', Strtotime ("$i Day $date"); Echo $day. " (". Getweek ($day).") \ n ";}
That's the effect, but what does the moderator define $date= ' 2014-09-29 ' do?
I understand that the landlord wants this week from Monday to Sunday ...
Header ("content-type:text/html; Charset=utf-8 ");
$timestamp =time ();
$is _return_timestamp=false;
Static $cache;
$id = $timestamp. $is _return_timestamp;
if (!isset ($cache [$id])) {
if (! $timestamp) $timestamp = time ();
$monday _date = Date (' y-m-d ', $timestamp -86400*date (' W ', $timestamp) + (date (' W ', $timestamp) >0?86400:-/*6*86400*/ 518400));
if ($is _return_timestamp) {
$cache [$id] = Strtotime ($monday _date);
}else{
$cache [$id] = $monday _date;
}
}
$Monday =strtotime ($cache [$id]);
$Tuesday = $Monday +3600*24*1;
$Wednesday = $Monday +3600*24*2;
$Thursday = $Monday +3600*24*3;
$Friday = $Monday +3600*24*2;
$Saturday = $Monday +3600*24*6;
$Sundany = $Monday +3600*24*6;
echo $cache [$id]. ' Monday
' ;
echo Date ("y-m-d", $Tuesday). ' Tuesday
';
echo Date ("y-m-d", $Wednesday). ' Wednesday
';
echo Date ("y-m-d", $Thursday). ' Thursday
';
echo Date ("y-m-d", $Friday). ' Friday
';
echo Date ("y-m-d", $Saturday). ' Saturday
';
echo Date ("y-m-d", $Sundany). ' Sunday
';
?>
$Saturday = $Monday +3600*24*5; This place is changed.
function Getweek ($day) { $days = array (' Sunday ', ' Monday ', ' Tuesday ', ' Wednesday ', ' Thursday ', ' Friday ', ' Saturday '); return $days [$day];} For ($i =0, $i <7; $i + +) { $a =strtotime ("+ $i Day"); $b =getweek (Date (' W ', $a)); $c =date (' y-m-d ', $a); echo "20$c$b
";}
2014-09-28 Sunday 2014-09-29 Monday 2014-09-30 Tuesday 2014-10-01 Wed 2014-10-02 Thursday 2014-10-03 Friday 2014-10-04 Saturday