Number of days in any given Month

To get the number of days in a given month we have to use cal_days_in_month function. Syntax is here:
cal_days_in_month(type of calendar, month, year )
Here is an example
$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

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 $m month :$no_of_days";
The output is here Number of days in 08 month :30You 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
Visitors Rating
Your Rating





Post your comments , suggestion , error , requirements etc here .




HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2019 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer