August 8, 2012

Current Week No. PHP Function

Current Week No. PHP Function


if(!function_exists('current_week_no'))
{
function current_week_no()
{
$current_date = date('Y-m-d');
$date_part = explode('-', $current_date);
$date_part[2] = '01';
$start_of_month = implode('-', $date_part);
$day_for_first = date('N', strtotime($start_of_month));
$day_for_month = date('j', strtotime($current_date));
$current_month_current_week = floor(($day_for_first + $day_for_month - 1) / 7) + 1;
$last_month = (date('m')-1);
$week_limit_of_last_month = $last_month*4;
$return = $week_limit_of_last_month+$current_month_current_week;
return $return;
}
}

Last updated: March 19, 2014
Did it helped? One thought on “Current Week No. PHP Function
  1. usman

    Hi your blog is awesome,it is very help full for beginners like me and Your work is just fantastic…….keep it up 🙂

Comments are closed.