Solarpitch Posted January 23, 2009 Share Posted January 23, 2009 Hi, Is it possible to get the start and end date of a week by simply pasing in the year? For example if the week number entered was week 1, could I set $week_start = "20090101" and $week_finish "20090107" in this format? Link to comment https://forums.phpfreaks.com/topic/142087-solved-getting-the-week-number-date/ Share on other sites More sharing options...
btherl Posted January 23, 2009 Share Posted January 23, 2009 If you use strtotime() I think you could do it. Eg $timestamp = strtotime("2009-01-01 +1 week"); Link to comment https://forums.phpfreaks.com/topic/142087-solved-getting-the-week-number-date/#findComment-744123 Share on other sites More sharing options...
Solarpitch Posted January 23, 2009 Author Share Posted January 23, 2009 Hi, I actually found this solution that works very well... <?php function week_start_date($wk_num, $yr, $first = 1, $format = 'F d, Y') { $wk_ts = strtotime('+' . $wk_num . ' weeks', strtotime($yr . '0101')); $mon_ts = strtotime('-' . date('w', $wk_ts) + $first . ' days', $wk_ts); return date($format, $mon_ts); } $sStartDate = week_start_date($week_number, $year); $sEndDate = date('F d, Y', strtotime('+6 days', strtotime($sStartDate))); ?> Link to comment https://forums.phpfreaks.com/topic/142087-solved-getting-the-week-number-date/#findComment-744131 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.