Home  >  Article  >  Backend Development  >  PHP function to get the timestamp of the first day of the specified month and the end of the last day

PHP function to get the timestamp of the first day of the specified month and the end of the last day

WBOY
WBOYOriginal
2016-07-23 08:54:551101browse
  1. /**
  2. * Get the timestamp of the first day of the specified month and the end of the last day
  3. *
  4. * @param int $y year $m month
  5. * @return array (start time of this month, end time of this month)
  6. */
  7. function mFristAndLast($y="",$m=""){
  8. if($y=="") $y=date("Y");
  9. if($m=="") $m=date("m");
  10. $m=sprintf("%02d",intval($m));
  11. $y=str_pad(intval($y),4,"0",STR_PAD_RIGHT);
  12. $m>12||$m<1?$m=1:$m=$m;
  13. $firstday=strtotime($y.$m."01000000");
  14. $firstdaystr=date("Y-m-01",$firstday);
  15. $lastday = strtotime(date('Y-m-d 23:59:59', strtotime("$firstdaystr +1 month -1 day")));
  16. return array("firstday"=>$firstday,"lastday"=>$lastday);
  17. }
复制代码

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