note 19512 modified in function.date by cece

From: Date: Wed, 20 Aug 2003 13:49:21 +0000
Subject: note 19512 modified in function.date by cece
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-54758@lists.php.net to get a copy of this message
function get_date_from_week($year, $week) { $first_day = strtotime($year."-01-01"); $is_monday = date("w", $first_day) == 1; $is_weekone = strftime("%V", $first_day) == 1; if($is_weekone) { $week_one_start = $is_monday ? $first_day : strtotime("last monday", $first_day); } else { $week_one_start = strtotime("next monday", $first_day); } return $week_one_start+(3600*24*7*($week-1)); } --was-- Whoops, accidently switched the order in the inline if. Here is the correct version :o) function get_date_from_week($year, $week) { $first_day = strtotime($year."-01-01"); $is_monday = date("w", $first_day) == 1; $is_weekone = strftime("%V", $first_day) == 1; if($is_weekone) { $week_one_start = $is_monday ? $first_day : strtotime("last monday", $first_day); } else { $week_one_start = strtotime("next monday", $first_day); } return $week_one_start+(3600*24*7*($week-1)); } http://www.php.net/manual/en/function.date.php

« previous php.notes (#54758) next »