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 03 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
Subscribe to our YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com



    Post your comments , suggestion , error , requirements etc here





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