PHP gets the number of days of the month and the first and last day of the month, the first day of the month, and the last day implementation method

Source: Internet
Author: User
Tags echo date

1.get the first day and last day of the month.
echo Date (' y-m-01 ', Strtotime ('-1 month '));
echo "<br/>";
echo Date (' Y-m-t ', Strtotime ('-1 month '));
echo "<br/>";
2.get the first day of the month and the last day.
$BeginDate =date (' y-m-01 ', Strtotime (date ("y-m-d"));
Echo $BeginDate;
echo "<br/>";
echo Date (' y-m-d ', Strtotime ("$BeginDate +1 month-1 Day");
echo "<br/>";
3.get the day of the year, month, day, and days.
echo "Total this month:". Date ("T"). " Days ";
echo "Current year". Date (' Y ');
echo "Current Month". Date (' m ');
echo "Current Date". Date (' d ');
echo "<br/>";
4.use functions and arrays to get the first day of the month and the last day, more practical
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);
}
$today = Date ("y-m-d");
$day =getthemonth ($today);
echo "The first day of the month:". $day [0]. "Last day of the month:". $day [1];
echo "<br/>";

---------------------------------------------------------------------

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

code as follows &NBSP;

function GetDays ($day) {
$lastday =date (' y-m-d ', Strtotime ("$day Sunday")); BR style= "margin:0px; padding:0px; " > $firstday =date (' y-m-d ', Strtotime ("$lastday-6 Days"));
return Array ($firstday, $lastday);
}
Print_r (getdays (' 2012-06-2 '));

PHP Gets the days of the month and the first and last day of the month, the first day of the month, and the last day of the implementation method

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.