note 78858 added to function.date

From: Date: Wed, 31 Oct 2007 05:17:31 +0000
Subject: note 78858 added to function.date
Groups: php.notes 
Request: Send a blank email to php-notes+get-131845@lists.php.net to get a copy of this message
I was looking for a function to find the week range for a particular week. But now I have developed by own. This function takes three arguments all optional 1. Week - This value ranges from 1- 52 or 53. It needs a correct value. If no value is provided, it then uses the current week. 2. Year - If none is provided, then the current year. 3. Format - defaults to d/M/Y It returns an array containing the 'start date' and the 'end date' Imp. Week starts from Sunday. function getWeekDateRange($week="",$year="",$format="d/M/Y"){ if($year=="" || !is_numeric($year)) $year=date("Y"); if($week=="" || !is_numeric($week)) $week=date("W"); $week--; $first_day=date("w",mktime(0,0,0,1,1,$year)); $first_day_tstamp=mktime(0,0,0,1,1,$year); $first_sunday=($first_day==0?0:(6-$first_day+1)); $first_sunday_tstamp=$first_sunday*24*3600+$first_day_tstamp; if($first_sunday!=0){ $week_cal=$week-1; }else{ $week_cal=$week; } $tw_start_tstamp=$first_sunday_tstamp+$week_cal*7*24*3600; $tw_end_tstamp=$first_sunday_tstamp+($week_cal+1)*7*24*3600-1; $yy=date("Y",$tw_end_tstamp); if($yy>$year) $tw_end_tstamp=mktime(23,59,59,12,31,$year); if($week==0 && $first_sunday!=0){ $tw_start_tstamp=$first_day_tstamp; $tw_end_tstamp=$first_sunday_tstamp-1; } $start_date=date($format,$tw_start_tstamp); $end_date=date($format,$tw_end_tstamp); return array($start_date,$end_date); } ---- Server IP: 203.199.69.133 Probable Submitter: 122.162.200.3 ---- Manual Page -- http://www.php.net/manual/en/function.date.php Edit -- https://master.php.net/note/edit/78858 Del: integrated -- https://master.php.net/note/delete/78858/integrated Del: useless -- https://master.php.net/note/delete/78858/useless Del: bad code -- https://master.php.net/note/delete/78858/bad+code Del: spam -- https://master.php.net/note/delete/78858/spam Del: non-english -- https://master.php.net/note/delete/78858/non-english Del: in docs -- https://master.php.net/note/delete/78858/in+docs Del: other reasons-- https://master.php.net/note/delete/78858 Reject -- https://master.php.net/note/reject/78858 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#131845) next »