In the query process, for example to check last month from the first day to the last day of the Commission (Commission), the US in the course of programming is to let the program range query in last month, the first day is relatively easy to handle, but at the end of the day is not fixed, to write a paragraph the function of month and year of judgment came last month the total number of days. It is in trouble, and get the current month of the current year, the conventional date acquisition function, the following code is correct by the engineers after the test code, you can rest assured that the use.
1. get the first and last day of last month.
Echo, date ('Y-m-01', strtotime ('-1, month'));
Echo, date ('Y-m-t', strtotime ('-1, month'));
2. get the first and last day of the month.
$BeginDate=date ('Y-m-01', strtotime (date ("Y-m-d"));
Echo date ('Y-m-d', strtotime ($BeginDate, +1, month, day, -1))
3. get the day, month, day and number of days.
Echo, "this month there are:".Date ("t"). "Heaven";
Echo current year.Date ('Y');
Echo current month.Date ('m');
Echo "current number".Date ('d');
4. use function and array to get the first and last day of the month, more practical, from friends.
Function getthemonth ($date)
$firstday = date ('Y-m-01', strtotime ($date));
$lastday = date ('Y-m-d', strtotime ($firstday, +1, month, day, -1))
Return, array ($firstday, $lastday);
$today = date ("Y-m-d");
Echo "the first day of the month:".$day., "the last day of the month:".$day;
PHP gets the number of days of the month and the first day of the month and the last day, the first day of the last month
- Yii2 XLS automatically upload and b2 years ago1040 Views
- PHP reflection mechanism to achieve2 years ago636 Views
- Laravel can create transfer paramet2 years ago1491 Views
- [Li Jingshan php] day laravel-2 years ago592 Views
- ThinkPHP5 debug configuration and v2 years ago766 Views
- Function that prevents SQL injectio2 years ago688 Views
- Install phpMyAdmin on CentOS2 years ago899 Views
- The difference between PHP, new, st2 years ago907 Views
- Adapter -PHP2 years ago1526 Views
- [Li Jingshan php] day laravel-2 years ago871 Views