I want to take a date and work out its week number.
So far, I have the following. It is returning 24 when it should be 42.
<?php
$ddate = "2012-10-18";
$duedt = explode("-",$ddate);
$date = mktime(0, 0, 0, $duedt[2], $duedt[1],$duedt[0]);
$week = (int)date('W', $date);
echo "Weeknummer: ".$week;
?>
Is it wrong and a coincidence that the digits are reversed? Or am I nearly there?
Just as a suggestion:
Might be a little simpler than all that lot.
Other things you could do:
Use PHP's date function
http://php.net/manual/en/function.date.php
Your code will work but you need to flip the 4th and the 5th argument.
I would do it this way
Also, your variable names will be confusing to you after a week of not looking at that code, you should consider reading http://net.tutsplus.com/tutorials/php/why-youre-a-bad-php-programmer/
try this solution
This get today date then tell the week number for the week
To get the week number for a date in North America I do like this:
and get:
Tue 2022-12-27: 53