Home >Backend Development >PHP Tutorial >php calculate how many days in a month

php calculate how many days in a month

王林
王林Original
2019-09-27 17:50:313737browse

php calculate how many days in a month

php calculates the number of days in a month

Format:

cal_days_in_month 的公用:返回某个历法中某年中某月的天数

Parameter introduction :

cal_days_in_month($par1,$par2,$par3);

$par1: A certain calendar used for calculation, PHP Calendar constant

$par2: Parameter $par1 selects a certain month in the calendar

$par3: Select a certain year in the calendar

Return value:

$par1 Select the number of days in a certain year and month in the calendar

PHP Calendar Constants: The calendar extension contains functions that simplify conversion between different calendar formats.

In order for these functions to work, you must compile PHP with --enable-calendar. Under window, support for calendar extension has been integrated

The constant CAL_GREGORIAN in the case is a predefined constant of PHP, just like PHP_OS and other constants

gregorian means: Gregorian calendar; Gregorian Calendar

Example:

<?php 
    $days = cal_days_in_month(CAL_GREGORIAN, 4, 2011);
    echo "返回2011-4的天数 ".$days."<br/>";
    $days = date(&#39;t&#39;, strtotime("2011-4-1"));
    echo "返回2011-4的天数 ".$days."<br/>";
    $days = date("t"); 
    echo "当前月的天数 ".$days."<br/>";
?>

Recommended tutorial:PHP video tutorial

The above is the detailed content of php calculate how many days in a month. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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