How to determine the ordinal number of the week of the year?

How to determine the ordinal number of the week of the year, knowing the date in the correct format?

For example, 12.03.2011: how do I get the ordinal number of the week out of it?

 3
php
Author: Nicolas Chabanovsky, 2011-03-12

3 answers

Function date can:

$test = strtotime("12.03.2011"); // тут может преобразование отличаться
echo "week: ".date("W", $test);
 4
Author: Алексей Сонькин, 2011-03-12 01:10:58

And if you do not use php functions, then something like this.

if((year%4)==0) value = (31*(month-1)-month/2+day)/7;
else{
    if(month>2) day = day-1;
    value = (31*(month-1)-month/2+day)/7;
}
 1
Author: greshnik, 2011-03-12 08:53:44
$data = new DateTime('2016-11-11');
echo $data->format('W');
 1
Author: Павел, 2016-11-11 10:03:59