php-general Digest 9 Jan 2013 10:22:15 -0000 Issue 8092

Topics (messages 320055 through 320058):

Re: Some date() oddities
        320055 by: Daniel Brown
        320056 by: Sebastian Krebs
        320057 by: Geoff Shang
        320058 by: Arno Kuhl

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
        php-gene...@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
On Tue, Jan 8, 2013 at 3:43 PM, Arno Kuhl <a...@dotcontent.net> wrote:
> I've bumped into an odd result with the date() function that I can't make
> sense of.
>
> Starting with a unix timestamp for 31 December 2012 13:12:12 (which is
> 1356952332) I calculate a week number:
>
> $ux_date = 1356952332;
>
> $weeknumber = date("W", $ux_date);   // returns 01 instead of 52

    Because, technically, 31 December was the second date of the
*fifty-third* week of 2012.  However, because the majority of the week
falls in 2013, it's rounded-in with that.

-- 
</Daniel P. Brown>
Network Infrastructure Manager
http://www.php.net/

--- End Message ---
--- Begin Message ---
Hi,

Workaround for what? The 31st of december is the first week of the
ISO8601-year 2013. That has nothing to do with PHP, date(), or any warnings
somebody left in the comments. Thats the way ISO8601 is defined:
http://en.wikipedia.org/wiki/ISO_8601#Week_dates

Regards,
Sebastian


2013/1/8 Arno Kuhl <a...@dotcontent.net>

> I've bumped into an odd result with the date() function that I can't make
> sense of.
>
>
>
> Starting with a unix timestamp for 31 December 2012 13:12:12 (which is
> 1356952332) I calculate a week number:
>
> $ux_date = 1356952332;
>
> $weeknumber = date("W", $ux_date);   // returns 01 instead of 52
>
>
>
> I found some warnings regarding ISO8601 for this in the user notes for the
> date() function in the PHP manual but couldn't see how this is managed in
> code, does anyone know of a workaround for this?
>
>
>
> Cheers
>
> Arno
>
>
>
>
>
>


-- 
github.com/KingCrunch

--- End Message ---
--- Begin Message ---
On Tue, 8 Jan 2013, Arno Kuhl wrote:

Starting with a unix timestamp for 31 December 2012 13:12:12 (which is
1356952332) I calculate a week number:

$ux_date = 1356952332;

$weeknumber = date("W", $ux_date);   // returns 01 instead of 52

I'm not that familiar with date, I tend to use strftime myself (no idea why there's both). Sounds like date's W is equivalent to strftime's %V which does indeed return "01" for this date as there's at least 4 days of the new year in that particular week.

Both %U and %W seem to return what you want, using strftime. I'd guess that date would also have flags for these.

Cheers,
Geoff.


--- End Message ---
--- Begin Message ---
On Tue, 8 Jan 2013, Arno Kuhl wrote:

> Starting with a unix timestamp for 31 December 2012 13:12:12 (which is
> 1356952332) I calculate a week number:
>
> $ux_date = 1356952332;
>
> $weeknumber = date("W", $ux_date);   // returns 01 instead of 52

I'm not that familiar with date, I tend to use strftime myself (no idea why
there's both).  Sounds like date's W is equivalent to strftime's %V which
does indeed return "01" for this date as there's at least 4 days of the new
year in that particular week.

Both %U and %W seem to return what you want, using strftime.  I'd guess that
date would also have flags for these.

Cheers,
Geoff.
--

Thanks Geoff, that's what I was looking for.

Cheers
Arno


--- End Message ---

Reply via email to