sponsor

Monday, January 12, 2009

how to get number of days in the month with php

if you want to know number of days in the month with php, you can call function cal_days_in_month()
this function returns the number of days in a given month, based on the calendar, month, and year that you specify

the format of this function is
Cal_days_in_month (calendar, Month, year)
This function have three parameters,
  • calendar, you can fill this parameter with CAL_GREGORIAN
  • month, you can fill this parameter with month (1 - 12)
  • year, you can fiil this parameter with 4 digits of year (2008)
example :
$days = cal_days_in_month(CAL_GREGORIAN, 1, 2009) ;
echo "In January 2009 there were $days days";
?>

that example will display
In january 2009 there were 31 days

No comments: