Home >Backend Development >PHP Problem >How to get the number of days in this month in php
php method to get the number of days in this month: 1. Create a PHP sample file; 2. Get the current date through "date('Y-m-d');"; 3. Use "date("t" ,strtotime($date));” method to get the number of days in this month.
The operating environment of this article: Windows 7 system, PHP version 7.1, Dell G3 computer.
How to get the number of days in this month in php?
The code is as follows:
<?php $date=date('Y-m-d'); echo $date; echo "<br>"; echo date("t",strtotime($date));
Output result:
2021-09-22 30
It can be concluded that the current time is 2021-09-22, then this month is the total number of September The number of days is 30 days.
Related introduction:
PHP date() function can format the timestamp into a more readable date and time.
Tip timestamp is a character sequence that represents the date/time when a certain event occurred.
Syntax
string date ( string $format [, int $timestamp ] )
Parameters
format Required. Specifies the format of the timestamp.
timestamp Optional. Specify timestamp. The default is the current date and time.
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to get the number of days in this month in php. For more information, please follow other related articles on the PHP Chinese website!