[Tfug] PHP calculating date from week
Adrian
choprboy at dakotacom.net
Tue Jun 20 16:46:17 MST 2006
On Tuesday 20 June 2006 14:59, Ammon Lauritzen 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);
Doh!!! Using strtotime in several steps to make a date... when I could have
just used the builtin function to make a date... dumb dumb dumb...
> 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.
Yep, saves a few cycles and definitely saves some script clutter. After
testing a number of times I am getting anywhere from a 20% decrease to a 4
fold increase in speed on one-off runs, a pretty consistent 20-25% increase
on a 10,000 integration loop... But of course, the single run time is only
about 1/10,000sec... so its hardly noticeable.
Thanks,
Adrian
More information about the tfug
mailing list