Page 1 of 1

getting # of days in a month

Posted: Thu Aug 25, 2005 3:11 pm
by psychotomus
how can I get the # of days in a month and what day the 1st of the month starts on?

Posted: Thu Aug 25, 2005 3:18 pm
by feyd
given a timestamp within the month in question:

Code: Select all

$time = mktime(12,34,56,7,8,2009);
$daysInMonth = date('t', $time);
$firstIsA = date('l',mktime(6,0,0,date('j',$time),1,date('Y',$time));

Posted: Thu Aug 25, 2005 3:22 pm
by Stewsburntmonkey
The last day of the month is the 0th day of the next month, so you can do this to print the number of days in a month:

Code: Select all

$lastday = mktime(0, 0, 0, 3, 0, 2000);
echo strftime("The number of days in Febuary in 2000 is: %d", $lastday);


To get the day of the week that a given date falls on use:

Code: Select all

date("l", mktime(0, 0, 0, 7, 1, 2000));


The above tells you what weekday July, 1st 2000 falls on. Just change the last 3 arguments to mktime() to suite your particular situation. :)

Posted: Thu Aug 25, 2005 3:24 pm
by psychotomus
thanks