Archive

Posts Tagged ‘t’

Find The Number Of Days For A Given Month With PHP

October 10th, 2008 No comments

There are two ways to find out the number of days for a given month. The first is to use the date() function in conjunction with the mktime() function to create a date and format this value as the number of days in a given month.

$monthDays = date("t",mktime(0,0,0,12,1,2008));

The second way is to use the function cal_days_in_month(). This function takes three parameters.

  • Canelday: There are a number of different forms of calendar to chose from. The one most English speaking people are interested in is the CAL_GREGORIAN calendar. Take a look at a full list of calendar constands.
  • Month: An integer representing the month (1 – 12).
  • Year: An integer representing the year.

So to find out the number of days in the month of December of 2008 you could use the following.

$monthDays = cal_days_in_month(CAL_GREGORIAN, 12, 2008);

Categories: PHP Tags: , , , , , , ,