search
Homephp教程PHP源码获得一段时间内所在的所有周的时间

php代码

<?
	/*  作用由起止日期算出其中的周
	 *  @param start_date 开始日期
	 *  @param end_date   结束日期
	 *  @return 一个二维数组,其中一维为每周起止时间
	 *  @author anngly
         *  @date 2013-06-08
         *  注意:end_date>state_date
	 **/
	
        function getWeek($startdate,$enddate)
	{
		//参数不能为空
		if(!empty($startdate) && !empty($enddate)){

			//先把两个日期转为时间戳
			$startdate=strtotime($startdate);
			$enddate=strtotime($enddate);
			//开始日期不能大于结束日期
			if($startdate<=$enddate){
				$end_date=strtotime("next monday",$enddate);
				if(date("w",$startdate)==1){
			      	$start_date=$startdate;
			    }else{
			      	$start_date=strtotime("last monday",$startdate);
			    }
			    //计算时间差多少周
			    $countweek=($end_date-$start_date)/(7*24*3600);
			    for($i=0;$i<$countweek;$i++){
			    	$sd=date("Y-m-d",$start_date);
			    	$ed=strtotime("+ 6 days",$start_date);
			    	$eed=date("Y-m-d",$ed);
			    	$arr[]=array($sd,$eed);
			    	$start_date=strtotime("+ 1 day",$ed);
			    }
			    return $arr;	
			}
		}
	}

	@var_dump(getWeek( "2012-08-04","2013-08-08")) ;
?>
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools