Week numbers

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Week numbers

Post by JayBird »

If i have a week number, say 47

How can i convert that to a unix timestamp for the begining of that week?

P.S. The year and month would also be availble to the script.

So i need to work out the timestamp, use the following as an example

week = 47
month = 11
year = 2004
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

Do a mktime() on the year, and then add (47*60*60*24*7).
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

Would that be 100% correct?
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

Umm probably not actually :S

You need to first see when the first monday of the year was - as that is when the first week should start counting from and then add that number of days onto the equation. I think that would then work 100% correct.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

how about working out the timestamp for the 1st monday of the year the using

strtotime("+47 weeks");

hmmmm....
Post Reply