hey all, need a little more help with some date manipulations.
(part 1) first date: october 1, 2004 number to add: 30 result: october 31, 2004
i have part 1 done and working awsome.
im trying to figure out how to do this:
(part 2) october 1 to october 30 = X weeks week x = x to x week y = x to x week z = x to x
and so on till it gets to the result date.
Originally posted by filn im trying to figure out how to do this: (part 2) october 1 to october 30 = X weeks week x = x to x week y = x to x week z = x to x and so on till it gets to the result date.
Couldn't you just take your number to add variable and divide it by 4.333333333.... (average number of weeks in a month) ?
$start = strtotime('Oct 1, 2004'); $end = strtotime('+30 days', $start); $week_num = 0; while (strtotime('+6 days', $start) < $end) { if (($next_week = strtotime('+6 days', $start)) < $end) { echo 'week ' . ++$week_num . ' = ' . date('m/d', $start) . ' to ' . date('m/d', $next_week) . '<br />'; $start = strtotime('+1 day', $next_week); } } if (strtotime('-1 day', $start) < $end) { echo 'week ' . ++$week_num . ' (partial) = ' . date('m/d', $start); if ($start != $end) { echo ' to ' . date('m/d', $end) . '<br />'; } }
...like:
$today = date("W", mktime(0, 0, 0, 10, 01, 2004));
$later = date("W", mktime(0, 0, 0, 10, 30, 2004));
$weeks = $later - $today;
thanks again everybody!!!!!!! your awsome!