Number of days in any given Month

$days = cal_days_in_month(CAL_GREGORIAN, 4, 2013);
echo "Number of days in  April  2013 = $days";
The output is here
Number of days in April 2013 = 30
Syntax is here:
cal_days_in_month(type of calendar, month, year )

Number of days in present month

There is a better way to get the number of days in present month by using date formats. Here is the code
echo date('t');
The output is here
31

Number of days in next month

We can read the present month and present year by using date() function. Then we will 1 to present month to get next month and then get the number of days in that month.
$m= date('m');// Present Month
$y= date('Y'); // Preseent year
$no_of_days = date('t',mktime(0,0,0,$m+1,1,$y)); 
// This is to calculate number of days in next month
echo " Number of days in Next to $m month :$no_of_days";
The output is here Number of days in Next to 10 month : 30
You can read more on date format here

Number of days in previous month

From the present month we can subtract 1 to get previous month
$no_of_days = date('t',mktime(0,0,0,$m-1,1,$y)); 
// to calculate number of days in previous month
strtotime: to get Date formats from a string input
Calendar Functions
Subhendu Mohapatra — author at plus2net
Subhendu Mohapatra

Author

🎥 Join me live on YouTube

Passionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.



Subscribe to our YouTube Channel here



plus2net.com











PHP video Tutorials
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
©2000-2025   plus2net.com   All rights reserved worldwide Privacy Policy Disclaimer