I am making a kalendar (date picker) and I was wondering how I can retrieve the number of days in the month. I can't go and declare the number of days for every month, thats too much code and not very effecient. thanx in advance, Zynex
Which language are you using? PHP or Javascript? For PHP you can use function getDays($year, $month){ static $arMonths = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); // Reduce the month number by 1 to match our array index $month--; //If the month is february and the year is leap return 29 else, return the corresponding element from the array return (((Year % 4 == 0 && Year % 100 != 0) || (Year % 400 == 0)) && $month == 1) 29 : $arMonths[$month]; } PHP:
The easy way is to create an array like $daysinmonth = array(31,28,31,30,31 etc) you can then display it with Echo "Jan has ".$daysinmonth[0]." days"; (it is always month number -1 since a array starts at 0). I know some years it could be a problem with feb, but ce la vie, this is the easy solution. you can always make more complicated solutions, for exampel ms sql dateadd and add a month and take then a datediff in days etc, but let's not complicate things good luck
In PHP you can date("t") to get the number of days in the given month: http://php.net/date HTH, cheers!