Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP iterate days of month given month and year [closed]

How can I print (echo) the days of an unknown month if month and year are parameters?

Thank you.

like image 992
Francisc Avatar asked Jan 22 '23 07:01

Francisc


2 Answers

To get the number of days in a given month of a given year you can use cal_days_in_month

echo cal_days_in_month(CAL_GREGORIAN, 10, 2010); // prints 31
like image 153
codaddict Avatar answered Feb 01 '23 07:02

codaddict


You can also use the date() function to get the number of days in a month. You can also pass the 2nd param strtotime() and specify a specific date:

$daysInMon = date('t', mktime(0, 0, 0, $month));
like image 24
kovalad Avatar answered Feb 01 '23 08:02

kovalad