Roee Posted July 26, 2010 Share Posted July 26, 2010 hello, I have a date which's format is: week-year For example, today is: 30-2010 which means that we're on the 30th week on 2010 How do I found the bounds of that week? For the 30th week in 2010, the bounds are: July 25 to July 31 THANKS ROEE~! Quote Link to comment https://forums.phpfreaks.com/topic/208958-dateweek/ Share on other sites More sharing options...
PFMaBiSmAd Posted July 26, 2010 Share Posted July 26, 2010 <?php $date = new DateTime(); $date->setISODate(2010, 30, 0); // July 25 echo $date->format("Y-m-d") . "<br />"; $date->setISODate(2010, 30, 6); // July 31 echo $date->format("Y-m-d") . "<br />"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/208958-dateweek/#findComment-1091441 Share on other sites More sharing options...
Roee Posted July 26, 2010 Author Share Posted July 26, 2010 exactly thanks alot Quote Link to comment https://forums.phpfreaks.com/topic/208958-dateweek/#findComment-1091446 Share on other sites More sharing options...
bh Posted July 26, 2010 Share Posted July 26, 2010 Hi, without DateTime() class, in "native PHP" heres a bit complexer but interesting eg date('Y-m-d', strtotime('2010W30')); // 2010/30th week's monday $sw = strtotime('2010W30'); date('Y-m-d', mktime(0, 0, 0, date('m', $sw), date('d', $sw) + 6, date('Y', $sw))); // prev week's end Quote Link to comment https://forums.phpfreaks.com/topic/208958-dateweek/#findComment-1091454 Share on other sites More sharing options...
jcbones Posted July 26, 2010 Share Posted July 26, 2010 The good thing about PHP is that it can be done multiple ways. <?php $sw = strtotime('2010W30'); echo date('m-d-Y',$sw) . '<br/>' . date('m-d-Y',strtotime('+6 days',$sw)); ?> Quote Link to comment https://forums.phpfreaks.com/topic/208958-dateweek/#findComment-1091476 Share on other sites More sharing options...
trq Posted July 26, 2010 Share Posted July 26, 2010 without DateTime() class, in "native PHP" From the DateTime class man page: There is no installation needed to use these functions; they are part of the PHP core. Quote Link to comment https://forums.phpfreaks.com/topic/208958-dateweek/#findComment-1091488 Share on other sites More sharing options...
bh Posted July 27, 2010 Share Posted July 27, 2010 @thorpe: Yeah, youre right, but im only gave to Roee another solution. Anyway with DateTime class its more elegant. Quote Link to comment https://forums.phpfreaks.com/topic/208958-dateweek/#findComment-1091571 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.