|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2003-01-10 16:14 UTC] trio at surffi dot saunalahti dot fi
I found out that date("W", $stamp) can gives a zero as output.
<?php
$stamp = time();
while( date("W", $stamp ) != 0 )
$stamp+=5000;
print date( "d.m.Y H:i W", $stamp ) . " $stamp\n";
?>
Out could be for examble "01.01.2005 00:46 0 1104533193".
I check the ISO-8601 standard (version 2000-12-19
ISO/TC 154 N 362) and it says:
calendar week is represented by two decimal digits. The first calendar week of a year shall be identified as
[01] and subsequent weeks shall be numbered in ascending sequence.
Futhermore the date function should have a option for 'normally' week number of the year like most of people does it understand practically: 1.1.xxxx is 1 and so on and finally 31.12.xxxx is 52.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 18:00:01 2025 UTC |
Unable to reproduce with script given, output of date("W") is always >= 1 and <= 53. (1) Could you try it with 4.3.0 and see if you get the same results? (2) What timezone are you in?This is a function what php needs for option to date function: function get_a_week( $timestamp ) { //Look the stamp for 1.1.xxxx 00:00:00 for current given stamp $seeking_stamp = mktime( 0, 0, 0, 1, 1, date( "Y", $timestamp ) ); //Week numbers are 1-52 in practically for( $i=1; $i < 53; $i++ ) { //Check if the passed stamp is between monday 00:00:00 and sunday 23:59:59 if( $timestamp => $seeking_stamp and $aika <= (($seeking_stamp+=7*24*3600)-1) ) return $i; //Found a week between 1-52 } //Should never get here return -1; }