Home > Backend Development > PHP Problem > How to get the number of days in this month in php

How to get the number of days in this month in php

藏色散人
Release: 2023-03-12 20:34:01
Original
7094 people have browsed it

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.

How to get the number of days in this month in php

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(&#39;Y-m-d&#39;);
echo $date;
echo "<br>";
echo date("t",strtotime($date));
Copy after login

Output result:

2021-09-22
30
Copy after login

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.

How to get the number of days in this month in php

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 ] )
Copy after login

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!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template