By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,729 Members | 1,363 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,729 IT Pros & Developers. It's quick & easy.

year week

P: n/a
bad
ive two variables the year and the week (2003 and 5) that means the 5th
week of the year 2003.
now i need the start- and enddate of the 5th week of year 2003.

i hope someone can help me to solve this problem.

Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
"bad" <d.***********@mervisoft.de> wrote in message
news:3F***************@mervisoft.de...
ive two variables the year and the week (2003 and 5) that means the 5th
week of the year 2003.
now i need the start- and enddate of the 5th week of year 2003.

i hope someone can help me to solve this problem.

You don't need the year to work this out as it will be the same for every
year.

$weekstart=$week*7;
$weekend=$week*7+7;

for $a=1; $a<=365; $a++) {
if($a>1 AND $a<=31) $month="Jan";
if($a>31 AND $a<=59) $month="Feb";
etc. etc. until Dec.
if($a==$weekstart) $startdate="$a $month";
if($a==$weekend) $enddate="$a $month";
}
Untested of course, but should crudely do the trick.
Richard Grove

http://shopbuilder.org - ecommerce systems
Become a Shop Builder re-seller:
http://www.affiliatewindow.com/affil...ls.php?mid=611
http://www.affiliatewindow.com/a.pl?590
Jul 17 '05 #2

P: n/a
Richard Grove wrote:
"bad" <d.***********@mervisoft.de> wrote in message
news:3F***************@mervisoft.de...
ive two variables the year and the week (2003 and 5) that means the
5th week of the year 2003.
now i need the start- and enddate of the 5th week of year 2003.


You don't need the year to work this out as it will be the same for
every year.


The start- and enddate depends on the year, so your code won't work - no
matter what it does.
Jul 17 '05 #3

P: n/a

On 3-Nov-2003, bad <d.***********@mervisoft.de> wrote:
ive two variables the year and the week (2003 and 5) that means the 5th
week of the year 2003.
now i need the start- and enddate of the 5th week of year 2003.

i hope someone can help me to solve this problem.


$year = 2003;
$week = 4;

// this assumes that the first week of the year starts on a Sunday
$weekoffset = $week-1; // make week offset zero based
$soytime = strtotime("1/1/$year"); // get the timestamp for the 1st day of
the year
$soyoffset = date('w',$soytime); // get the number of days past sunday
$soydatetime = strtotime("-$soyoffset day",$soytime); // get the timestamp
for the sunday before or == to the start date of the year
$soweektime = strtotime("+$weekoffset week",$soydatetime); // get the
timestamp for the sunday of the week

$startOfWeek = date('m/d/Y',$soweektime); // convert the timestamp to a date
$endOfWeek = date('m/d/Y',strtotime("+1 week",$soweektime)); // add a week
and convert to a date

--
Tom Thackrey
www.creative-light.com
tom (at) creative (dash) light (dot) com
do NOT send email to ja*********@willglen.net (it's reserved for spammers)
Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.