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

WBOY
Release: 2016-07-25 09:05:27
Original
1465 people have browsed it
  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 placesA simple example of how many decimal places to keep in PHPHow to round decimals in PHP (with examples)Three ways to implement two decimal places in php



source:php.cn
Statement of this Website
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!