tkm Posted June 27, 2008 Share Posted June 27, 2008 Hello Mates, Need a small help. Can anyone provide me insights or some few lines of code on how can I get month's name from providing the week and year information. Say I want to know the name of the month of 2nd week of year 2008. Any help would be greatly appreciated. Thank you. Link to comment https://forums.phpfreaks.com/topic/112176-month-name-from-week-and-year/ Share on other sites More sharing options...
thebadbad Posted June 27, 2008 Share Posted June 27, 2008 It's not as easy as you would think. Found some threads about it, have a look: http://tech.groups.yahoo.com/group/phpexperts/message/4639 http://forums.devshed.com/php-development-5/date-of-the-first-day-from-a-given-week-number-64740.html http://tzzz.wordpress.com/2006/08/14/8/ Link to comment https://forums.phpfreaks.com/topic/112176-month-name-from-week-and-year/#findComment-575863 Share on other sites More sharing options...
thebadbad Posted June 27, 2008 Share Posted June 27, 2008 From the comments of the last link, there's an easy solution working at my box (PHP 5.2.2, Apache on WinXP): <?php $week = 2; $year = 2008; $week = str_pad($week, 2, 0, STR_PAD_LEFT); $month = date('F', strtotime($year . 'W' . $week)); echo $month; ?> This echoes the month on the first day of the specified week (on my box, may be system dependent). So week 1 would output December, since week 1 started in December, 2007 (2007-12-31). Link to comment https://forums.phpfreaks.com/topic/112176-month-name-from-week-and-year/#findComment-575868 Share on other sites More sharing options...
Rowno Posted June 27, 2008 Share Posted June 27, 2008 That's easy to do once you have a Unix timestamp. I'm assuming that you know the number of weeks into the year so to get the month number you will need to divide that by 4 (you may need to round it down by using floor() ). Now you can make a Unix timestamp by using the mktime(hour,minute,second,month,day,year) function and the month number and year (you can fill parameters you don't need like hour, day etc with 0). Then you can easily use the date() function to get the month's name like this: <?php date("F", $timestamp); ?> Link to comment https://forums.phpfreaks.com/topic/112176-month-name-from-week-and-year/#findComment-575874 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.