note 80092 modified in function.date by danbrown

From: Date: Sun, 17 May 2009 19:02:30 +0000
Subject: note 80092 modified in function.date by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-155196@lists.php.net to get a copy of this message
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) --was-- 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 http://php.net/manual/en/function.date.php

« previous php.notes (#155196) next »