getting # of days in a month
Moderator: General Moderators
-
psychotomus
- Forum Contributor
- Posts: 487
- Joined: Fri Jul 11, 2003 1:59 am
getting # of days in a month
how can I get the # of days in a month and what day the 1st of the month starts on?
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
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));-
Stewsburntmonkey
- Forum Commoner
- Posts: 44
- Joined: Wed Aug 24, 2005 2:09 pm
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:
To get the day of the week that a given date falls on use:
The above tells you what weekday July, 1st 2000 falls on. Just change the last 3 arguments to mktime() to suite your particular situation.
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.