note 81962 added to function.mktime

From: Date: Fri, 21 Mar 2008 14:05:54 +0000
Subject: note 81962 added to function.mktime
Groups: php.notes 
Request: Send a blank email to php-notes+get-137264@lists.php.net to get a copy of this message
Another useful function that I have created years ago. Useful for all calendar applications, if you have to switch to a date given by a week number and a specific day (e.g. tuesday in week 12: mktimefromcw(2008, 12, 2)). /** * @return timestamp * @param integer year * @param integer woy * @param integer dow * @desc This function retrieves the time for the given year, week of year and day of the week and returns it. */ function mktimefromcw($year, $woy=1, $dow=1) { # $year = year (four digits) # $woy = week of the year (1..53) # $dow = day of the week (1..7) $dow = ($dow) % 7; $woy = ($woy) - 1; # Get reference value (this is the first monday of the first week of the year, not easy to calculate) $fdoy_timestamp = mktime(0,0,0,1,1,$year); $fdoy = ((date("w", $fdoy_timestamp) + 6) % 7) + 1; if($fdoy == 1) { # This first day of the year is a monday $fcwstart = $fdoy_timestamp; } elseif($fdoy < 5) { # The first day if before Friday, therefor the first Monday can be found in the previos year (this is no fun, believe in it!). $fcwstart = strtotime("last Monday", $fdoy_timestamp); } else { # The first day is a friday or later, so the first days belong to calender week 53 (yes, this is possible!) of the previous year, do not count them for this year. $fcwstart = strtotime("next Monday", $fdoy_timestamp); } # Create timestamp $timestr = date("d F Y", $fcwstart)." +$woy week +$dow day"; $time = strtotime($timestr); # Return timestamp return $time; } ---- Server IP: 212.124.37.9 Probable Submitter: 81.210.160.62 ---- Manual Page -- http://www.php.net/manual/en/function.mktime.php Edit -- https://master.php.net/note/edit/81962 Del: integrated -- https://master.php.net/note/delete/81962/integrated Del: useless -- https://master.php.net/note/delete/81962/useless Del: bad code -- https://master.php.net/note/delete/81962/bad+code Del: spam -- https://master.php.net/note/delete/81962/spam Del: non-english -- https://master.php.net/note/delete/81962/non-english Del: in docs -- https://master.php.net/note/delete/81962/in+docs Del: other reasons-- https://master.php.net/note/delete/81962 Reject -- https://master.php.net/note/reject/81962 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#137264) next »