Re: SOS - How to get the number of a week
| From: | Julian Wood | Date: | Thu, 26 Oct 2000 07:18:00 +0000 |
| Subject: | Re: SOS - How to get the number of a week | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-22074@lists.php.net to get a copy of this message | ||
on 10/25/00 3:23 PM, Thomas Deliduka at thomas@neweve.com wrote:
>
> 53 weeks in a year? never heard of that. And doesn't the week start on
> Sunday? That's how all my calendars show it.
52 wks * 7 days/wk = 364 days so there can easily be the beginnings of a
53rd week. Weeks can start on Mondays or Sundays by convention. Choice is
yours, but here in NA it is typically Sunday.
>
> Sorry I don't have any information on this question specifically, if I have
> some time I will do some reseach.
>
> On 10/25/00 3:03 PM this was written:
>
>> I give an SOS to the world ...
>>
>> How can I get the fisrt and last days for a given week :
>> Week = 40 of 2000 ===> first = monday 10/2/2000 last Sunday 10/8/2000
Presumably you have an actual date that you can use as a starting reference?
If you do you can do date calculations using mktime and date (find out what
day of the week it is and subtract that from your ref date).
eg echo date ("w", mktime (0,0,0,10,26,2000)); // 4
echo date ("m/d/Y", mktime (0,0,0,10,26-4,2000)); // 10/22/2000
If you don't have a starting date, try this:
echo date ("w", mktime (0,0,0,1,40*7,2000)); // 5
echo date ("m/d/Y", mktime (0,0,0,1,40*7-5,2000)); // 10/01/2000
This is assuming your week starts on Sunday.
>>
>> It's more difficult when the week is beetween december and january or
>> when there are 53 weeks a year!
>> 12/31/2001 is first day of week 1 - 2002
>> 12/30/2002 is first day of week 1 - 2003
>>
mktime will take care of these problems automatically. Look in the php
manual for more examples.
Julian
--
Multimedia Developer
Perceptions Consulting