根据周数从星期一获取日期[关闭]

根据周数从星期一获取日期[关闭]

问题描述:

I can`t figure out the code to get the date from monday depending on the week number of this year.

could someone help me with this code?

thanks.

根据今年的周数,我无法找出从星期一开始的日期代码。

有人可以帮我这个代码吗? p>

谢谢。 p> div>

This will provide the Monday of a certain week this year:

$thisYear = date('Y');
$weekNum = 40;

$date = date('Y-m-d', strtotime("$thisYear-W$weekNum-1"));  // Outputs 2013-09-30

I have this laying around (I'm not sure if I or someone else was the original author) but give it a try:

  $week = 34; //Enter your week here.

  $week = mktime( 0, 0, 0, 1, 1,  2013 ) + ( $week * 7 * 24 * 60 * 60 ); 

  $monday = $week - 86400 * ( date( 'N', $week ) - 1 );
  $monday = date( 'Y-m-d', $monday );

  echo $monday;

Use DateTime class :

$dt = new DateTime;
$dt->setISODate($year, $week);
echo $dt->format('Y-m-d');

demo