PHP gets a few examples of the first and last days of the month on which the specified date is located

Source: Internet
Author: User

Sample code

The code is as follows

Gets the first and last day of the month on which the specified date is located
function Getthemonth ($date) {
$firstday = Date ("y-m-01", Strtotime ($date));
$lastday = Date ("y-m-d", Strtotime ("$firstday +1 month-1 Day"));
Return Array ($firstday, $lastday);
}

Sample code

PHP gets the first and last day of the week of the specified date

The code is as follows

function GetDays ($day) {
$lastday =date (' y-m-d ', Strtotime ("$day Sunday"));
$firstday =date (' y-m-d ', Strtotime ("$lastday-6 Days"));
Return Array ($firstday, $lastday);
}
Print_r (getdays (' 2012-06-2 '));

Sample code

code as follows  

$date = date to process
* $step 0 = this month, positive and negative indicates the month before and after the month date
* $date = The month to process
* Enter description ...
*/
Function assigntabmonth ($date, $step) {
$date = date ("y-m-d", Strtotime ($step. "Months", Strtotime ($date) )//The date of the processing (the date before and after the month)
$u _date = Strtotime ($date);
$days =date ("T", $u _date); Number of days to get the result month

//Date of the first day of the month
$first _date=date ("Y-m", $u _date). ' -01 ';
for ($i =0; $i < $days; $i + +) {
$for _day=date ("y-m-d", Strtotime ($first _date) + ($i *3600*24));
}
return $first _date. ' to '. $for _day;

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.