Forum Moderators: coopster
im looking to create a kinda gantt chart effect on screen by taking a date range and splitting it into its individual weeks
04/01/2008 - 30/01/2008
so this would be weeks 1 - 4 (im looking for yyyy/ww format)
2008/01
2008/02
2008/03
2008/04
I would then have a table with columns for 52 weeks of the year, i can then colour in the date range on the table - colour weeks 1 - 4
could anyone set me off in the right direction with doing the split correctly?
In the US also see ANSI X3.30 and NIST FIPS 4-1. In the UK also see BS EN 28601, and EN 28601 throughout Europe.
is there something i can do with
strtotime
monday of week 23 kind of thing?
using date('N'), you can also get the day of the week (1-Mon through 7-Sun).
Then useing something like '1 - date('N', timestamp)', 0 meaning the day is monday else the difference.
then with your date use strtotime("date -{difference} days")
or 'if (difference > 0) strtotime("date last Monday")'
Hope this helps.
<?php
$target = strtotime("2008-01-01");
echo"<br>".$target;
$thedate = date('W',"$target");
echo"<br>".$thedate;
echo"<Br>".date('W');
function week($year, $week)
{
$from = date("Y-m-d", strtotime("{$year}-W{$week}-1")); //Returns the date of monday in week
$to = date("Y-m-d", strtotime("{$year}-W{$week}-7")); //Returns the date of sunday in week
return "Week {$week} in {$year} is from {$from} to {$to}.";
}
$counter=1;
while($counter!==53){
echo"<br>".$counter;
if(strlen($counter)==1){
$string1=0;
$correntcounter=$string1.$counter;
}
if(strlen($counter)==2){
$correntcounter=$counter;
}
echo"<br>".week(2008,$correntcounter);
//Returns: Week 27 in 2008 is from 2008-06-30 to 2008-07-06.
$counter++;
}
?>