jmaccs64 Posted August 20, 2006 Share Posted August 20, 2006 Hello,Can some please help me simplify this? Thanks!!!![code]//This will find current week $today = date("YmdHis"); $week_array = array(20060819230300, 20060819231400, 20060924100000); if ($today<$week_array[0]) {$week = "1";} elseif ($today<$week_array[1]) {$week = "2";} elseif ($today<$week_array[2]) {$week = "3";} else {$week= "0";}[/code] Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted August 20, 2006 Share Posted August 20, 2006 What is it supposed to do? Quote Link to comment Share on other sites More sharing options...
Barand Posted August 20, 2006 Share Posted August 20, 2006 Quite!You would expect an array of dates each 7 days apart, but that has 2 dates same (19th) then the 24th ??? ??? ???Here's a couple of options[code]<?php// METHOD 1 - assumes weeks start on a Monday//// if first day of month is in week 31 of the year // and today is in 33rd week // then we're in 3rd week of the month////$weekfirst = date('W', mktime(0,0,0,date('m'),1,date('Y')));$week = date('W')-$weekfirst+1;// METHOD 2 - assumes weeks start on first day of current month//// days 1-7 of month in first week // 8 - 14 in 2nd week // 15 - 21 in 3rd week// 22 - 28 in 4th week//$week = 1 + floor((date('j') - 1)/7);?>[/code] Quote Link to comment Share on other sites More sharing options...
jmaccs64 Posted August 20, 2006 Author Share Posted August 20, 2006 This will have about 19 dates in it. These dates are for the start date and time of each week of the NFL season, each week the first game time could be different, hence why i can't use the week function of date() Thanks! Any suggestions? Quote Link to comment Share on other sites More sharing options...
jmaccs64 Posted August 21, 2006 Author Share Posted August 21, 2006 This is what i figured out...does anyone see any problem with this code? THANKS[code]//This will find current week $today = date("YmdHis"); $week_array = array(1 => 20060907173000, 20060917100000, 20060924100000, 20061001100000, 20061008100000, 20061015100000, 20061022100000, 20061029100000, 20061105100000, 20061112100000, 20061119100000, 20061123093000, 20061130170000, 20061207170000, 20061214170000, 20061221170000, 20061230170000); $week_array_count = count($week_array); $i = 1; while(($i <= $week_array_count) && (!$week)){ if($today<$week_array[$i]){ $week="$i"; }; $i++; }[/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.