How PHP gets a list of dates for a period of time

Source: Internet
Author: User

A recent project on the timeline, giving a start time and an end time, you need to list the dates in this time period and also determine how many weeks. After research, come up with the following methods, and we share, to facilitate the need for friends.

First, the effect of this demand map:

The following is a specific code fragment:


* * Parameters are start timestamp, end timestamp
/function Timelist ($beginTimeStamp, $endTimeStamp) {
	if!is_numeric ($ Begintimestamp)!is_numeric ($endTimeStamp) ($endTimeStamp <= $beginTimeStamp)) return "";
	$tmp =array ();
    for ($i = $beginTimeStamp; $i <= $endTimeStamp; $i + = (24*3600)) {
		$tmp ["Timestamplist"][]= $i;
        $tmp ["Daylist"][]=date ("Y-year m-month D-Day", $i);
		$tmp ["DayWeek"][]=getweek ($i);
    }
	return $tmp;
}
function Getweek ($timestamp) {
	$timestamp =date ("W", $timestamp);
	$str = "";//http://www.alixixi.com/php-function/969.html
	switch ($timestamp) {case
		"0":
			$str. = "Sunday";
		break;
		Case "1":
			$str. = "Monday";
		break;
		Case "2":
			$str. = "Tuesday";
		break;
		Case "3":
			$str. = "Wednesday";
		break;
		Case "4":
			$str. = "Thursday";
		break;
		Case "5":
			$str. = "Friday";
		break;
		Case "6":
			$str. = "Saturday";
		break;
	return $str;
}

Articles that you may be interested in

    • PHP gets the method for each month over a period of time, returning an array of these months
    • How PHP Gets the start time stamp and end time stamp for today, yesterday, last week, month
    • PHP gets a list of dates 30 days before the current date
    • Why the programmer estimates the time and the project actually completes the time always has the error
    • PHP Gets the list of all the pictures in the content and outputs the method
    • PHP implementation to instantly output the results to the browser
    • PHP Gets the Ganzhi annals, Zodiac and constellation information based on a date or time stamp
    • PHP extracts the birthday date in the ID number and the function to verify that it is a minor


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.