Home  >  Article  >  Backend Development  >  How to get date based on year and week number in php

How to get date based on year and week number in php

WBOY
WBOYOriginal
2016-07-25 09:05:271535browse
  1. function getWeekDate($year,$weeknum){
  2. $firstdayofyear=mktime(0,0,0,1,1,$year);
  3. $firstweekday=date('N', $firstdayofyear);
  4. $firstweenum=date('W',$firstdayofyear);
  5. if($firstweenum==1){
  6. $day=(1-($firstweekday-1))+7*($weeknum-1 );
  7. $startdate=date('Y-m-d',mktime(0,0,0,1,$day,$year));
  8. $enddate=date('Y-m-d',mktime(0,0, 0,1,$day+6,$year));
  9. }else{
  10. $day=(9-$firstweekday)+7*($weeknum-1);
  11. $startdate=date('Y-m-d', mktime(0,0,0,1,$day,$year));
  12. $enddate=date('Y-m-d',mktime(0,0,0,1,$day+6,$year));
  13. }
  14. return array($startdate,$enddate);
  15. }
  16. ?>
Copy code

Articles you may be interested in: php number_format() retains the number of decimal places A simple example of how many decimal places to keep in PHP How to round decimals in PHP (with examples) Three ways to implement two decimal places in php



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn