Get date from monday depending on week number [closed]

女生的网名这么多〃 提交于 2019-12-13 09:42:52

问题


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.


回答1:


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



回答2:


Use DateTime class :

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

demo




回答3:


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;


来源:https://stackoverflow.com/questions/18599330/get-date-from-monday-depending-on-week-number

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!