Current location: Hot Scripts Forums » Programming Languages » PHP » Need day of year from ISO-8601 week number.


Need day of year from ISO-8601 week number.

Reply
  #1 (permalink)  
Old 01-16-04, 07:24 AM
matt.simpson matt.simpson is offline
Newbie Coder
 
Join Date: Jan 2004
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Need day of year from ISO-8601 week number.

Hello,
Subject pretty much says it.

I haven't a clue of how to go about doing this accuratly.

Basically, I have an ISO-8601 week number, ie: 47 and the year, ie: 2004

I need to know any of the 7 days of year, ie: 124 (preferrably the first day) of that week...

If anyone has a light to shed, please post.

Thanks,
Matt Simpson
Reply With Quote
  #2 (permalink)  
Old 01-20-04, 01:04 PM
YourPHPPro's Avatar
YourPHPPro YourPHPPro is offline
Community VIP
 
Join Date: Aug 2003
Posts: 430
Thanks: 0
Thanked 0 Times in 0 Posts
Would this help ?

Code:
matt at crx4u dot com
30-Oct-2002 06:53

Here's a pair of functions to convert a date to an ISO 8601 year/week and vice versa.

function yearweek($date="") {
   if (!$date) $date = mktime();
   $yearweek =  strftime("%G%V", $date);
   return $yearweek;
}

function dateEndYearweek($yearweek) {
   $weekEndDay = 0;  // 0 = Sunday.
   $year = (int) substr($yearweek, 0, 4);
   $week = (int) substr($yearweek, -2, 2);
   // We know that the 4th Jan is always in week 01, 11th Jan in week 02, ...
   // so day (4 + (w-1)*7) is in week w.
   $dayOfYear = 4 + (($week - 1) * 7);
   $date = mktime(0, 0, 0, 1, $dayOfYear, $year);
   // Find the last day of this week.
   $dayOfWeek = date("w", $date);
   $daysToAdd = ($weekEndDay - $dayOfWeek + 7) % 7;
   $date += $daysToAdd * 24*60*60;
   return $date;
}
http://www.php.net/strftime
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP.NET: Day / Work Week / Week / Month web calendar control with view like MS Outloo gicio ASP.NET 2 06-09-04 02:12 AM
BUG - number of members surebetdmg HotScripts Site Bug Reports 2 08-10-03 04:35 PM
auto number superman PHP 1 06-30-03 09:53 AM


All times are GMT -5. The time now is 08:31 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.