note 79694 added to function.date

From: Date: Sat, 08 Dec 2007 19:19:29 +0000
Subject: note 79694 added to function.date
Groups: php.notes 
Request: Send a blank email to php-notes+get-132956@lists.php.net to get a copy of this message
It has already been said that date() does only count up to week52 but it's really annoying. date('W',strtotime('2007-12-30')) returns 52 date('W',strtotime('2007-12-31')) returns 1 but Monday of Week 1 of Year 2007 is the 01.01.2007 This is totally wrong. Here's my solution: <?php function getweek($date='') { if ($date=='') { return false; } $y = date('Y', strtotime($date)); $m = date('n', strtotime($date)); $d = date('j', strtotime($date)); #check-date $cd = mktime(0,0,0,$m,$d,$y); #last monday of the year (credits to jcwebb at dicoe dot com) $lm = strtotime('last Monday',mktime(0,0,0,12,32,$y)); #If we are within the last week of the year #and date('W') would return 1, return 53 #otherwise just do what date('W') does (there's no week 54) if ((date('Ymd',$cd) >= date('Ymd',$lm)) && date('W',$cd) == 1) { return 53; } else { return (int)date('W',$cd); } } echo getweek('2007-12-31'); ?> ---- Server IP: 217.13.201.10 Probable Submitter: 80.141.108.252 ---- Manual Page -- http://www.php.net/manual/en/function.date.php Edit -- https://master.php.net/note/edit/79694 Del: integrated -- https://master.php.net/note/delete/79694/integrated Del: useless -- https://master.php.net/note/delete/79694/useless Del: bad code -- https://master.php.net/note/delete/79694/bad+code Del: spam -- https://master.php.net/note/delete/79694/spam Del: non-english -- https://master.php.net/note/delete/79694/non-english Del: in docs -- https://master.php.net/note/delete/79694/in+docs Del: other reasons-- https://master.php.net/note/delete/79694 Reject -- https://master.php.net/note/reject/79694 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#132956) next »