In the process of doing the query, for example, to realize the last month from the first day to the last day of Commission (Commission), then we in the program implementation process to let the program in the scope of the last month to query, the first day is relatively good, but the last day is uncertain, To write the function of the month and the year to determine the number of days before the last month. That's more than trouble. Gets the regular date of the current month, the current year, and the following code is the correct code after testing the company's engineers, you can rest assured that use.
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, from netizens.
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 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