note 56156 deleted from function.date by nlopess

From: Date: Fri, 02 Sep 2005 09:41:25 +0000
Subject: note 56156 deleted from function.date by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-94650@lists.php.net to get a copy of this message
Note Submitter: sandved at gmail dot com ---- The format parameter 'W' which return the ISO Week, do not follow the ISO standard (ISO 8601), since it return the first 9 weeks without a leading zero. Use this for returning current week with leading zeros $ISOweek = substr('0' . date('W') , -2); Here's an example returning the ISO year if you're running an earlier versiuon of PHP than 5.1 (were tou can use the parameter 'o'): (I'm quite new to PHP, so the code can be a bit 'bad') <?php //if OK // $datetext = "28 December 2003"; //2003-W52-7 // $datetext = "29 December 2003"; //2004-W01-1 //elseif OK $datetext = "3 January 1999"; //1998-W53-7 // $datetext = "4 January 1999"; //1999-W01-1 // $ISOweek = substr('0' . date('W',strtotime($datetext)) , -2); if ((date('d',strtotime($datetext))>=29) && (date('m',strtotime($datetext))==12) && (date('W',strtotime($datetext))==1)) { $ISOyearweek = date('Y',strtotime($datetext)) + 1 . '-W' . $ISOweek; } elseif ((date('d',strtotime($datetext))<=3) && (date('m',strtotime($datetext))==1) && (date('W',strtotime($datetext))==53)) { $ISOyearweek = date('Y',strtotime($datetext)) - 1 . '-W' . $ISOweek; } else { $ISOyearweek = date('Y',strtotime($datetext)) . ' -W' . $ISOweek; } echo $datetext,"<BR>"; echo "Date: " . date('Y-m-d',strtotime($datetext)),"<BR>"; echo "Week: " . $ISOyearweek,"<BR>"; ?> More on converting in accordance with ISO 8601, see http://www.pvv.org/~nsaa/ISO8601.html

« previous php.notes (#94650) next »