Get week number and year from a Unix timestamp in php
<p>I am trying to create a weekly calendar that allows the user to advance or go back a week.  So far I have this...</p>

<pre><code>&lt;?
if(isset($_POST['add_week'])){
     $last_week_ts = strtotime($_POST['last_week']);
     $display_week_ts = $last_week_ts + (3600 * 24 * 7);
} else if (isset($_POST['back_week'])) {
     $last_week_ts = strtotime($_POST['last_week']);
     $display_week_ts = $last_week_ts - (3600 * 24 * 7);
} else {
    $display_week_ts = floor(time() / (3600 * 24)) * 3600 * 24;
}

    $week_start = date('d-m-Y', $display_week_ts);
    $week_number = date("W", strtotime( $display_week_ts));
    $year = date("Y", strtotime( $display_week_ts));

echo $week_start.' '.$week_number.' '.$year;
?&gt;

&lt;table name="week"&gt;
    &lt;tr&gt;
&lt;?
for($day=1; $day&lt;=7; $day++)
{
    echo '&lt;td&gt;';
    echo date('d-m-Y', strtotime($year."W".$week_number.$day))." | \n";
    echo '&lt;/td&gt;';
}
?&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;form name="move_weeks" method="post" action="&lt;?php echo $_SERVER['PHP_SELF']; ?&gt;"&gt;
&lt;input type="hidden" name="last_week" value="&lt;? echo $week_start; ?&gt;" /&gt;
&lt;td colspan="7"&gt;&lt;input type="submit" name="back_week" value="back_week" /&gt;&lt;input type="submit" name="add_week" value="add_week" /&gt;
&lt;/td&gt;
&lt;/form&gt;
&lt;/tr&gt;
&lt;/table&gt;
</code></pre>

<p>The the back and forward buttons work just fine and the $week_start variable which represents the first date of the week advances and goes back as it should but regardless of the date shown the $week_number and $year show as 01 and 1970 or 36 and 1600.</p>

<p>I know it must be something to do with the way I have tried to extract them from $display_week_ts but I don't know what</p>
