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? Quote Link to comment 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"); Quote Link to comment 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))); ?> Quote Link to comment 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.