First date of the week

I want the first day of the week to say that I have 45th week. Now I want to have the date of the first Sunday this week. Can anyone suggest me how can I do this?

thanks

+3
source share
6 answers

Search a bit, the most recommended is:

$year = "2009"; // date("Y");
$week = "45"; // date("W");

$firstDayOfWeek = strtotime($year."W".str_pad($week,2,"0",STR_PAD_LEFT));

print("The first day of week ".$week." of ".$year." is ".date("D, d-m-Y",$firstDayOfWeek));

It basically comes down to having strtotime do the work for you. You fill out "2009W45" and it will receive a date for you. Pitfall here is that the week should be in a two-digit format. So week 1 should be 01, so str_pad will fill in zero.

+4
source

strtotime date

,

$next_sunday = strtotime('next sunday');
$next_week = strtotime('+1 week');
$next_sunday_of_next_week = strtotime('next sunday', $next_week);

,

+1

, :

$timestamp = mktime(0, 0, 0, $month, $day, $year);
 echo date('c', $timestamp) = mktime(0, 0, 0, $month, date('d', $timestamp)-date('w', $timestamp), $year);

, :

echo $date('c', mktime(0, 0, 0, $month, date('d', $timestamp)-date('w', $timestamp), $year));

: http://pinoytech.org/blog/post/get-the-first-day-of-the-week-with-an-exact-date

0

date($str_format, strtotime($year."W".$week."1"))

$str_format - PHP date() function. 'M d Y'

0

, .

0

, , . , , script ?

-1

Source: https://habr.com/ru/post/1722078/


All Articles