I want to get the week numbers for given two dates i.e from 2012-01-01 to 2012-12-31.The week numbers should fall exactly in the range as specified above.Can u please give suggestions for doing this.
Something like this should work fine:
<?php
$startDateUnix = strtotime('2012-01-01');
$endDateUnix = strtotime('2013-01-01');
$currentDateUnix = $startDateUnix;
$weekNumbers = array();
while ($currentDateUnix < $endDateUnix) {
$weekNumbers[] = date('W', $currentDateUnix);
$currentDateUnix = strtotime('+1 week', $currentDateUnix);
}
print_r($weekNumbers);
?>
DEMO.
Output:
Array
(
[0] => 52
[1] => 01
[2] => 02
.........
[51] => 51
[52] => 52
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With