Current location: Hot Scripts Forums » Programming Languages » PHP » how can i display all the weeks


how can i display all the weeks

Reply
  #1 (permalink)  
Old 03-17-10, 06:16 AM
zee000 zee000 is offline
Newbie Coder
 
Join Date: Feb 2010
Posts: 21
Thanks: 2
Thanked 0 Times in 0 Posts
how can i display all the weeks

hi

i need a code to display the week no`s with dates as seen below for the present year..

week1 (01-07)
week2(08-15)
...week52or53(25-31)...

thanks in advance
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 03-17-10, 07:09 AM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,516
Thanks: 20
Thanked 109 Times in 106 Posts
You could use PHP: strtotime - Manual to get the timestamp for the first day of the year, then use PHP: date - Manual to loop through the weeks of the year.

PHP Code:

$currentweek=strtotime('01/01/2010 00:00:001');

$nextweek=strtotime('+1 week',$currentweek);
echo 
date('W',$nextweek); 
Not tested.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 03-17-10, 07:32 AM
zee000 zee000 is offline
Newbie Coder
 
Join Date: Feb 2010
Posts: 21
Thanks: 2
Thanked 0 Times in 0 Posts
i have tried that but it does not work ...

have u tried that code ...........
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 03-24-10, 06:18 PM
Jcbones Jcbones is offline
Aspiring Coder
 
Join Date: Mar 2009
Location: North Carolina, USA
Posts: 516
Thanks: 5
Thanked 47 Times in 44 Posts
It needs tweaked, but I'll let you have a go at it first.

PHP Code:

<?php
$year 
date('Y');
for(
$i 1$i 54$i++) {
    
$n = ($i 10) ? $i $i;
    
$start date('d',strtotime($year.'W'.$n '1'));
    
$end date('d',strtotime($year.'W'.$n.'7'));
    
    
$weeks[$n] = "($start - $end)";
}

foreach(
$weeks as $key => $value) {
    echo 
"Week $key $value \n<br/>";
}
?>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump


All times are GMT -5. The time now is 01:14 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.