note 50187 added to function.date
| From: | vasu at osu1 dot php dot net | Date: | Mon, 21 Feb 2005 13:45:12 +0000 |
| Subject: | note 50187 added to function.date | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-85308@lists.php.net to get a copy of this message | ||
Hello, I am having some problem with the date functions. For your information i am using PHP Version
4.2.3 which is compiled on a HP UX.
I want to write a code which convers the string data 'YYWW' into 'YYMM' format.
ex: '0430' -> '0407' since 30th week comes in 07 month it got translated into
'0407'.
I had posted about this problem on other forums but couldnt get much help there. The code which i
got from other forum is:
<?php
$yearweek='0414';
$year=substr($yearweek,0,2);
$week=substr($yearweek,2);
$unixtime=mktime(0,0,0,1,(($week-1)*7),$year);
echo date('ym',strtotime('last monday',$unixtime));
?>
The above code works good for 2004 year, but again when i change the value of $yearweek to
'0510' i get the return value as '0502' where as it should have been
'0503'. If the remove the '-1' in line 5 then for 2005 and rest years it works
but for 2004 it doesnt.
I thought this problem was because of the 2004 being leap year but i was wrong. I tried to make
condition which checks for the year being leap year or not. But this too didnt helped me.
I dont know how i can solve this problem and will be very glad if anyone can help me in this matter.
Thanks.
P.s: also, i am using PHP Version 4.2.3 running on HP UX
----
Manual Page -- http://www.php.net/manual/en/function.date.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+50187
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+50187&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+50187&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+50187&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+50187&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+50187&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+50187&report=yes
Search -- http://master.php.net/manage/user-notes.php