note 80092 deleted from function.date by tularis
| From: | tularis@php.net | Date: | Thu, 09 Feb 2012 21:01:46 +0000 |
| Subject: | note 80092 deleted from function.date by tularis | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-186011@lists.php.net to get a copy of this message | ||
Note Submitter: ZZigc
----
I wanted to get the number of weeks for particular year.
Example with date():
<?php
$weeks_in_year = date("W", strtotime("12/31/2007"));
?>
It works for years smaller than current year, but returns '01' when year was the same or
bigger as current year.
Not sure if I missed something or maybe misused this function but I couldn't get it to work
even with different date representations.
So the workaround was using different function.
Example with strftime():
<?php
$weeks_in_year = strftime("%W",strtotime("12/31/2007"));
?>
Now it works as a charm.
PHP v.4.4.7
[EDIT BY danbrown AT php DOT net: In a note dated 25-JAN-09, "Juan Paredes" offered the
following information as an amendment.]
Complementing the information [in this note], if you want to calculate the number of weeks in a
given year, according to the week definition by ISO 8601, the following should be enough:
date('W', mktime(0,0,0,12,28,$year) );
(the last week on a give year always contains 28-Dec)