[Tfug] PHP calculating date from week

Judd Pickell pickell at gmail.com
Tue Jun 20 15:05:50 MST 2006


Wow, I didn't know mktime supported greater than 31 for the day parameter.
(although having gone back to read the documentation I see it there now..
Boy do I feel stupid.. hahaha)

I would go with Ammon's suggestion.. :)

On 6/20/06, Ammon Lauritzen <ammon at simud.org> wrote:
>
> Adrian wrote:
> > Anybody have a simple week to date function in PHP worked out? I have
> been
> > banging my head trying to figure out something simple... without 20
> lines of
> > recursive logic to handle corner cases...
>
> Ok, let's see if I can think long enough to write this out for you :P
>
> $weekstamp = mktime(0,0,0,1,$week*7,$year);
>
> This gives a unix timestamp for midnight on the week x7th day of the
> year and should probably save you a few cycles wasted making two
> strtotime() calls.
>
> I'd then use localtime($weekstamp)["tm_wday"] to get the day of the week
> in stead of date("w"), it's probably a touch faster.
>
> Ammon
>
> _______________________________________________
> Tucson Free Unix Group - tfug at tfug.org
> Subscription Options:
> http://www.tfug.org/mailman/listinfo/tfug_tfug.org
>



More information about the tfug mailing list