Write a PHP function to get start and end date of a week (by week number) of a particular year

  • برمجة بي اتش بي

Write a PHP function to get start and end date of a week (by week number) of a particular year.

الأجوبة

<?php
function Start_End_Date_of_a_week($week, $year)
{
    $time = strtotime("1 January $year", time());
	$day = date('w', $time);
	$time += ((7*$week)+1-$day)*24*3600;
	$dates[0] = date('Y-n-j', $time);
	$time += 6*24*3600;
	$dates[1] = date('Y-n-j', $time);
	return $dates;
}

$result = Start_End_Date_of_a_week(12,2014);
echo 'Starting date of the week: '. $result[0]."\n";
echo 'End date the week: '. $result[1];
?>

Sample Output:

Starting date of the week: 2014-3-24                        
End date the week: 2014-3-30
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...