Number of days in a month

PHP provides functions to get the number of days in a month for a specified year and calendar. We can use date(‘t’) or cal_days_in_month().

date('t')

t‘ in date(‘t’) is date format option which gives number of days in the given month.

Example
1. date(‘t’) returns number of days in current month

2. Returns number of days in a given month. We can given any date of that month.

cal_days_in_month

The cal_days_in_month() function returns the number of days in a month for a specified year and calendar. It is supported in PHP 4 >= 4.1.0, PHP 5.

Syntax

Parameters
1. calendar: Required, Calendar to use for calculation
2. month: Required, Month in the selected calendar
3. year: Required, Year in the selected calendar

Example:

You Might Interested In

Leave a Reply

Enclose a code block like: <pre><code>Your Code Snippet</code></pre>.