Canman2005 Posted January 22, 2008 Share Posted January 22, 2008 Hi all I have a form which posts a month & year such as mypage?month=3&year=2009 What I need to do is take the month and year which with the above is 3/2009 (march 2009) and then print every day which is in that month, so with the date 3/2009 (march 2009) it would output 31 <font>1/3/2009</font> <font>2/3/2009</font> <font>3/3/2009</font> <font>4/3/2009</font> <font>5/3/2009</font> <font>6/3/2009</font> <font>7/3/2009</font> <font>8/3/2009</font> <font>9/3/2009</font> <font>10/3/2009</font> <font>11/3/2009</font> <font>12/3/2009</font> <font>13/3/2009</font> <font>14/3/2009</font> <font>15/3/2009</font> ........ and so on and then when the url that is posted is mypage?month=4&year=2009 it would output <font>1/4/2009</font> <font>2/4/2009</font> <font>3/4/2009</font> .... and so on. Is this possible? Any help would be ace Thanks Dave Quote Link to comment https://forums.phpfreaks.com/topic/87239-printing-days-in-month/ Share on other sites More sharing options...
aebstract Posted January 22, 2008 Share Posted January 22, 2008 for ($day = 1; $day <= 31; $day++) { echo "<font>$day/4/2009</font>"; } Something like that will work. To determine how many days it does, you change the 31. Need a little script that takes the set month and sets a variable for that 31 depending on the month. Quote Link to comment https://forums.phpfreaks.com/topic/87239-printing-days-in-month/#findComment-446242 Share on other sites More sharing options...
p2grace Posted January 22, 2008 Share Posted January 22, 2008 To get the number of days in a month: $month_days = cal_days_in_month(CAL_GREGORIAN,$month,$year); Quote Link to comment https://forums.phpfreaks.com/topic/87239-printing-days-in-month/#findComment-446244 Share on other sites More sharing options...
aebstract Posted January 22, 2008 Share Posted January 22, 2008 for ($day = 1; $day <= $month_days; $day++) { echo "<font>$day/$month/$year</font>"; } Updated code to go along with p2grace's code. If you put his first, this will do what you want. Quote Link to comment https://forums.phpfreaks.com/topic/87239-printing-days-in-month/#findComment-446245 Share on other sites More sharing options...
kenrbnsn Posted January 22, 2008 Share Posted January 22, 2008 You can use the date() function in conjunction with the strtotime() function to get the number of days in a month: <?php $days_in_month = date('t',strtotime($_GET['year'] . '-' . $_GET['month'] . '-1')); for ($i=1;$i<=$days_in_month;$i++) echo '<font>' . $i . '/' . $_GET['month'] . '/' . $_GET['year'] . "</font>\n"; ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/87239-printing-days-in-month/#findComment-446246 Share on other sites More sharing options...
revraz Posted January 22, 2008 Share Posted January 22, 2008 This may help as well http://php.about.com/od/finishedphp1/ss/php_calendar.htm Quote Link to comment https://forums.phpfreaks.com/topic/87239-printing-days-in-month/#findComment-446255 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.