Calcular los días que tiene un mes con PHP
Posted on Jueves, marzo 4th, 2010 at 12:24Si necesitas contar los dias que tiene un mes, y no cuentas con el paquete Calendar y la funcion cal_days_in_month() Entonces esto sera muy util.
/* * daysInMonth($month, $year) * Devuelve la cantidad de dias que tiene un mes en un año determinado. * * $month: numero de mes (integers 1-12) * $year: numero de año (any integer) ('aaaa') * * Prec: $month y $year deben ser integer. * Post: none */ function daysInMonth($month, $year) { // Calculo la cantidad de dias en el mes return $month == 2 ? ($year % 4 ? 28 : ($year % 100 ? 29 : ($year % 400 ? 28 : 29))) : (($month - 1) % 7 % 2 ? 30 : 31); }
Espero que le sirva, Saludos.


Leave a reply