Fog Juice Posted January 18, 2008 Share Posted January 18, 2008 How can I get the first day of the week? I am not good with dates. I'm trying to create a function where you input the week number and the year, and it will return the timestamp of the first sunday of that week. So for example, if you wanted to input week 12 of year 2007, it would return the timestamp of the sunday of that week. Quote Link to comment https://forums.phpfreaks.com/topic/86610-solved-how-do-i-get-the-first-day-of-the-week/ Share on other sites More sharing options...
Fog Juice Posted January 18, 2008 Author Share Posted January 18, 2008 i am in a bit of a time pinch, i'm supposed to be programming a schedule for a medical office that should have been finished a few days ago. This is one thing that i'm stuck on, i'd really really appreciate some help. Quote Link to comment https://forums.phpfreaks.com/topic/86610-solved-how-do-i-get-the-first-day-of-the-week/#findComment-442573 Share on other sites More sharing options...
pdkv2 Posted January 18, 2008 Share Posted January 18, 2008 Use the following function function getSundayOfGivenWeek($week,$year){ $sunday = strtotime('+' . 6 . ' days', strtotime('-' . (date('w', strtotime($year . '0104 +' . ($week - 1). ' weeks')) - 1) . ' days',strtotime($year . '0104 +' . ($week - 1). ' weeks'))); return $sunday; } echo strftime('%A-%Y/%m/%d', getSundayOfGivenWeek(12,2007)); Regards Sharad Quote Link to comment https://forums.phpfreaks.com/topic/86610-solved-how-do-i-get-the-first-day-of-the-week/#findComment-442595 Share on other sites More sharing options...
vbnullchar Posted January 18, 2008 Share Posted January 18, 2008 <?php function getDaysInWeek ($weekNumber, $year) { // Count from '0104' because January 4th is always in week 1 // (according to ISO 8601). $time = strtotime($year . '0104 +' . ($weekNumber - 1) . ' weeks'); // Get the time of the first day of the week $mondayTime = strtotime('-' . (date('w', $time) - 1) . ' days', $time); // Get the times of days 0 -> 6 $dayTimes = array (); for ($i = 0; $i < 7; ++$i) { $dayTimes[] = strtotime('+' . $i . ' days', $mondayTime); } // Return timestamps for mon-sun. return $dayTimes; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/86610-solved-how-do-i-get-the-first-day-of-the-week/#findComment-442597 Share on other sites More sharing options...
vbnullchar Posted January 18, 2008 Share Posted January 18, 2008 <?php function getDaysInWeek ($weekNumber, $year) { // Count from '0104' because January 4th is always in week 1 // (according to ISO 8601). $time = strtotime($year . '0104 +' . ($weekNumber - 1) . ' weeks'); // Get the time of the first day of the week $mondayTime = strtotime('-' . (date('w', $time) - 1) . ' days', $time); // Get the times of days 0 -> 6 $dayTimes = array (); for ($i = 0; $i < 7; ++$i) { $dayTimes[] = strtotime('+' . $i . ' days', $mondayTime); } // Return timestamps for mon-sun. return $dayTimes; } $dayTimes = getDaysInWeek(33, 2006); foreach ($dayTimes as $dayTime) { echo (strftime('%a %Y%m%d', $dayTime) . "n"); } ?> from http://tzzz.wordpress.com/2006/08/14/8/ Quote Link to comment https://forums.phpfreaks.com/topic/86610-solved-how-do-i-get-the-first-day-of-the-week/#findComment-442602 Share on other sites More sharing options...
Fog Juice Posted January 18, 2008 Author Share Posted January 18, 2008 thank you all for your help Quote Link to comment https://forums.phpfreaks.com/topic/86610-solved-how-do-i-get-the-first-day-of-the-week/#findComment-442612 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.