Jump to content

Printing days in month


Canman2005

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/87239-printing-days-in-month/
Share on other sites

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.